mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05: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>
36 lines
861 B
JavaScript
36 lines
861 B
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 filename = path.join(common.tmpDir, 'write.txt');
|
|
const expected = Buffer.from('hello');
|
|
let openCalled = 0;
|
|
let writeCalled = 0;
|
|
|
|
|
|
common.refreshTmpDir();
|
|
|
|
fs.open(filename, 'w', 0o644, function(err, fd) {
|
|
openCalled++;
|
|
if (err) throw err;
|
|
|
|
fs.write(fd, expected, 0, expected.length, null, function(err, written) {
|
|
writeCalled++;
|
|
if (err) throw err;
|
|
|
|
assert.equal(expected.length, written);
|
|
fs.closeSync(fd);
|
|
|
|
var found = fs.readFileSync(filename, 'utf8');
|
|
assert.deepEqual(expected.toString(), found);
|
|
fs.unlinkSync(filename);
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(1, openCalled);
|
|
assert.equal(1, writeCalled);
|
|
});
|