mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 05:21:19 +00:00

Several changes: * Soft-Deprecate Buffer() constructors * Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()` * Add `--zero-fill-buffers` command line option * Add byteOffset and length to `new Buffer(arrayBuffer)` constructor * buffer.fill('') previously had no effect, now zero-fills * Update the docs PR-URL: https://github.com/nodejs/node/pull/4682 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
28 lines
666 B
JavaScript
28 lines
666 B
JavaScript
'use strict';
|
|
const assert = require('assert');
|
|
const common = require('../common');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
|
|
const fileName = path.resolve(dirName, 'test.bin');
|
|
|
|
var buf = Buffer.alloc(512 * 1024, 42);
|
|
|
|
try {
|
|
fs.mkdirSync(dirName);
|
|
} catch (e) {
|
|
// Ignore if the directory already exists.
|
|
if (e.code != 'EEXIST') throw e;
|
|
}
|
|
|
|
fs.writeFileSync(fileName, buf);
|
|
|
|
fs.readFile(fileName, function(err, data) {
|
|
assert.ifError(err);
|
|
assert(data.length == buf.length);
|
|
assert.strictEqual(buf[0], 42);
|
|
|
|
fs.unlinkSync(fileName);
|
|
fs.rmdirSync(dirName);
|
|
});
|