mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 20:08:02 +00:00

It is a maintenance burden that was removed from the docs in 2010 (c93e0aaf06
) and runtime-deprecated in v6.0 (1124de2d76
). 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>
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
'use strict';
|
|
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 = Buffer.from('xyz\n');
|
|
|
|
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));
|