mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +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>
22 lines
501 B
JavaScript
22 lines
501 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var stream = require('stream');
|
|
var Buffer = require('buffer').Buffer;
|
|
|
|
var r = new stream.Readable();
|
|
r._read = function(size) {
|
|
r.push(Buffer.allocUnsafe(size));
|
|
};
|
|
|
|
var w = new stream.Writable();
|
|
w._write = function(data, encoding, cb) {
|
|
cb(null);
|
|
};
|
|
|
|
r.pipe(w);
|
|
|
|
// This might sound unrealistic, but it happens in net.js. When
|
|
// `socket.allowHalfOpen === false`, EOF will cause `.destroySoon()` call which
|
|
// ends the writable side of net.Socket.
|
|
w.end();
|