mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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>
This commit is contained in:
@@ -9,7 +9,7 @@ var bench = common.createBenchmark(main, {
|
||||
n: [25e4]
|
||||
});
|
||||
|
||||
var UTF_ALPHA = 'Blåbærsyltetøy';
|
||||
var UTF_ALPHA = 'Blåbærsyltetøy';
|
||||
var ASC_ALPHA = 'Blueberry jam';
|
||||
|
||||
function main(conf) {
|
||||
@@ -35,18 +35,18 @@ function main(conf) {
|
||||
|
||||
for (i = 0; i < inLen; ++i) {
|
||||
if (i > 0 && (i % chunkLen) === 0 && !isBase64) {
|
||||
chunks.push(new Buffer(str, encoding));
|
||||
chunks.push(Buffer.from(str, encoding));
|
||||
str = '';
|
||||
}
|
||||
str += alpha[i % alpha.length];
|
||||
}
|
||||
if (str.length > 0 && !isBase64)
|
||||
chunks.push(new Buffer(str, encoding));
|
||||
chunks.push(Buffer.from(str, encoding));
|
||||
if (isBase64) {
|
||||
str = new Buffer(str, 'utf8').toString('base64');
|
||||
str = Buffer.from(str, 'utf8').toString('base64');
|
||||
while (str.length > 0) {
|
||||
var len = Math.min(chunkLen, str.length);
|
||||
chunks.push(new Buffer(str.substring(0, len), 'utf8'));
|
||||
chunks.push(Buffer.from(str.substring(0, len), 'utf8'));
|
||||
str = str.substring(len);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user