diff options
author | James M Snell <jasnell@gmail.com> | 2016-01-25 15:00:06 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-16 08:34:02 -0700 |
commit | 85ab4a5f1281c4e1dd06450ac7bd3250326267fa (patch) | |
tree | 7a51edfc5d6efc231cf821d575c9ca4a26d0545f /test/parallel/test-stream2-writable.js | |
parent | 90a5fc20be22b4278a01bc58acba0cb732da0140 (diff) | |
download | android-node-v8-85ab4a5f1281c4e1dd06450ac7bd3250326267fa.tar.gz android-node-v8-85ab4a5f1281c4e1dd06450ac7bd3250326267fa.tar.bz2 android-node-v8-85ab4a5f1281c4e1dd06450ac7bd3250326267fa.zip |
buffer: add .from(), .alloc() and .allocUnsafe()
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>
Diffstat (limited to 'test/parallel/test-stream2-writable.js')
-rw-r--r-- | test/parallel/test-stream2-writable.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 81e57d06eb..062e69f78c 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -154,7 +154,7 @@ test('write bufferize', function(t) { chunks.forEach(function(chunk, i) { var enc = encodings[ i % encodings.length ]; - chunk = new Buffer(chunk); + chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); t.end(); @@ -168,7 +168,7 @@ test('write no bufferize', function(t) { tw._write = function(chunk, encoding, cb) { assert(typeof chunk === 'string'); - chunk = new Buffer(chunk, encoding); + chunk = Buffer.from(chunk, encoding); return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; @@ -191,7 +191,7 @@ test('write no bufferize', function(t) { chunks.forEach(function(chunk, i) { var enc = encodings[ i % encodings.length ]; - chunk = new Buffer(chunk); + chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); t.end(); @@ -235,7 +235,7 @@ test('end callback', function(t) { test('end callback with chunk', function(t) { var tw = new TestWriter(); - tw.end(new Buffer('hello world'), function() { + tw.end(Buffer.from('hello world'), function() { t.end(); }); }); @@ -249,7 +249,7 @@ test('end callback with chunk and encoding', function(t) { test('end callback after .write() call', function(t) { var tw = new TestWriter(); - tw.write(new Buffer('hello world')); + tw.write(Buffer.from('hello world')); tw.end(function() { t.end(); }); @@ -258,7 +258,7 @@ test('end callback after .write() call', function(t) { test('end callback called after write callback', function(t) { var tw = new TestWriter(); var writeCalledback = false; - tw.write(new Buffer('hello world'), function() { + tw.write(Buffer.from('hello world'), function() { writeCalledback = true; }); tw.end(function() { @@ -274,7 +274,7 @@ test('encoding should be ignored for buffers', function(t) { t.equal(chunk.toString('hex'), hex); t.end(); }; - var buf = new Buffer(hex, 'hex'); + var buf = Buffer.from(hex, 'hex'); tw.write(buf, 'binary'); }); @@ -335,7 +335,7 @@ test('dont end while writing', function(t) { assert(wrote); t.end(); }); - w.write(Buffer(0)); + w.write(Buffer.alloc(0)); w.end(); }); @@ -352,7 +352,7 @@ test('finish does not come before write cb', function(t) { assert(writeCb); t.end(); }); - w.write(Buffer(0)); + w.write(Buffer.alloc(0)); w.end(); }); @@ -366,7 +366,7 @@ test('finish does not come before sync _write cb', function(t) { assert(writeCb); t.end(); }); - w.write(Buffer(0), function(er) { + w.write(Buffer.alloc(0), function(er) { writeCb = true; }); w.end(); @@ -380,6 +380,6 @@ test('finish is emitted if last chunk is empty', function(t) { w.on('finish', function() { t.end(); }); - w.write(Buffer(1)); - w.end(Buffer(0)); + w.write(Buffer.allocUnsafe(1)); + w.end(Buffer.alloc(0)); }); |