diff options
author | Nikolai Vavilov <vvnicholas@gmail.com> | 2017-01-10 14:26:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 14:26:23 +0200 |
commit | 3c2a9361ffd797acd6c9f5a09ae01648aa0e9792 (patch) | |
tree | 7b755d0c03e0e62713d9629b14f123e323378547 /test/parallel/test-fs-read.js | |
parent | 2685464e34731d9ea14e97616309f4e7b7292551 (diff) | |
download | android-node-v8-3c2a9361ffd797acd6c9f5a09ae01648aa0e9792.tar.gz android-node-v8-3c2a9361ffd797acd6c9f5a09ae01648aa0e9792.tar.bz2 android-node-v8-3c2a9361ffd797acd6c9f5a09ae01648aa0e9792.zip |
fs: remove fs.read's string interface
It is a maintenance burden that was removed from the docs in 2010
(c93e0aaf062081db3ec40ac45b3e2c979d5759d6) and runtime-deprecated in v6.0
(1124de2d76ad7118267d91a08485aa928a5f0865).
PR-URL: https://github.com/nodejs/node/pull/9683
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-read.js')
-rw-r--r-- | test/parallel/test-fs-read.js | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index 41957c228e..733be5ba0d 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -2,21 +2,34 @@ const common = require('../common'); const assert = require('assert'); const path = require('path'); +const Buffer = require('buffer').Buffer; const fs = require('fs'); const filepath = path.join(common.fixturesDir, 'x.txt'); const fd = fs.openSync(filepath, 'r'); -const expected = 'xyz\n'; -fs.read(fd, - expected.length, - 0, - 'utf-8', - common.mustCall((err, str, bytesRead) => { - assert.ifError(err); - assert.strictEqual(str, expected); - assert.strictEqual(bytesRead, expected.length); - })); +const expected = Buffer.from('xyz\n'); -var r = fs.readSync(fd, expected.length, 0, 'utf-8'); -assert.strictEqual(r[0], expected); -assert.strictEqual(r[1], expected.length); +function test(bufferAsync, bufferSync, expected) { + fs.read(fd, + bufferAsync, + 0, + expected.length, + 0, + common.mustCall((err, bytesRead) => { + assert.ifError(err); + assert.strictEqual(bytesRead, expected.length); + assert.deepStrictEqual(bufferAsync, Buffer.from(expected)); + })); + + const r = fs.readSync(fd, bufferSync, 0, expected.length, 0); + assert.deepStrictEqual(bufferSync, Buffer.from(expected)); + assert.strictEqual(r, expected.length); +} + +test(Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(expected.length), + expected); + +test(new Uint8Array(expected.length), + new Uint8Array(expected.length), + Uint8Array.from(expected)); |