buffer: remove deprecated Buffer.write branch
* Explit throw on deprecated Buffer.write(...) * Update tests, remove obsolete Buffer.write(...) * Add comment for obsolete Buffer.write(...) PR-URL: https://github.com/nodejs/node/pull/5048 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9aebb002b0
commit
2c55cc2d2c
@ -2,7 +2,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const binding = process.binding('buffer');
|
const binding = process.binding('buffer');
|
||||||
const internalUtil = require('internal/util');
|
|
||||||
const bindingObj = {};
|
const bindingObj = {};
|
||||||
|
|
||||||
exports.Buffer = Buffer;
|
exports.Buffer = Buffer;
|
||||||
@ -522,10 +521,6 @@ Buffer.prototype.fill = function fill(val, start, end) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var writeWarned = false;
|
|
||||||
const writeMsg = 'Buffer.write(string, encoding, offset, length) is ' +
|
|
||||||
'deprecated. Use write(string[, offset[, length]]' +
|
|
||||||
'[, encoding]) instead.';
|
|
||||||
Buffer.prototype.write = function(string, offset, length, encoding) {
|
Buffer.prototype.write = function(string, offset, length, encoding) {
|
||||||
// Buffer#write(string);
|
// Buffer#write(string);
|
||||||
if (offset === undefined) {
|
if (offset === undefined) {
|
||||||
@ -550,14 +545,12 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
|
|||||||
encoding = length;
|
encoding = length;
|
||||||
length = undefined;
|
length = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX legacy write(string, encoding, offset, length) - remove in v0.13
|
|
||||||
} else {
|
} else {
|
||||||
writeWarned = internalUtil.printDeprecationMessage(writeMsg, writeWarned);
|
// if someone is still calling the obsolete form of write(), tell them.
|
||||||
var swap = encoding;
|
// we don't want eg buf.write("foo", "utf8", 10) to silently turn into
|
||||||
encoding = offset;
|
// buf.write("foo", "utf8"), so we can't ignore extra args
|
||||||
offset = length >>> 0;
|
throw new Error('Buffer.write(string, encoding, offset[, length]) ' +
|
||||||
length = swap;
|
'is no longer supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
var remaining = this.length - offset;
|
var remaining = this.length - offset;
|
||||||
|
@ -351,10 +351,10 @@ assert.equal(rangeBuffer.toString({toString: function() {
|
|||||||
// testing for smart defaults and ability to pass string values as offset
|
// testing for smart defaults and ability to pass string values as offset
|
||||||
var writeTest = new Buffer('abcdes');
|
var writeTest = new Buffer('abcdes');
|
||||||
writeTest.write('n', 'ascii');
|
writeTest.write('n', 'ascii');
|
||||||
writeTest.write('o', 'ascii', '1');
|
writeTest.write('o', '1', 'ascii');
|
||||||
writeTest.write('d', '2', 'ascii');
|
writeTest.write('d', '2', 'ascii');
|
||||||
writeTest.write('e', 3, 'ascii');
|
writeTest.write('e', 3, 'ascii');
|
||||||
writeTest.write('j', 'ascii', 4);
|
writeTest.write('j', 4, 'ascii');
|
||||||
assert.equal(writeTest.toString(), 'nodejs');
|
assert.equal(writeTest.toString(), 'nodejs');
|
||||||
|
|
||||||
// ASCII slice test
|
// ASCII slice test
|
||||||
@ -895,7 +895,7 @@ assert.equal(0, Buffer('hello').slice(0, 0).length);
|
|||||||
assert.equal(buf[3], 0x63);
|
assert.equal(buf[3], 0x63);
|
||||||
|
|
||||||
buf.fill(0xFF);
|
buf.fill(0xFF);
|
||||||
written = buf.write('abcd', 'utf8', 1, 2); // legacy style
|
written = buf.write('abcd', 1, 2, 'utf8');
|
||||||
console.log(buf);
|
console.log(buf);
|
||||||
assert.equal(written, 2);
|
assert.equal(written, 2);
|
||||||
assert.equal(buf[0], 0xFF);
|
assert.equal(buf[0], 0xFF);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user