Skip to content

Commit 0ae7810

Browse files
dcposchMichael Scovetta
authored and
Michael Scovetta
committed
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: nodejs#5048 Reviewed-By: Brian White <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 30ef314 commit 0ae7810

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

lib/buffer.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
const binding = process.binding('buffer');
5-
const internalUtil = require('internal/util');
65
const bindingObj = {};
76

87
exports.Buffer = Buffer;
@@ -522,10 +521,6 @@ Buffer.prototype.fill = function fill(val, start, end) {
522521
};
523522

524523

525-
var writeWarned = false;
526-
const writeMsg = 'Buffer.write(string, encoding, offset, length) is ' +
527-
'deprecated. Use write(string[, offset[, length]]' +
528-
'[, encoding]) instead.';
529524
Buffer.prototype.write = function(string, offset, length, encoding) {
530525
// Buffer#write(string);
531526
if (offset === undefined) {
@@ -550,14 +545,12 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
550545
encoding = length;
551546
length = undefined;
552547
}
553-
554-
// XXX legacy write(string, encoding, offset, length) - remove in v0.13
555548
} else {
556-
writeWarned = internalUtil.printDeprecationMessage(writeMsg, writeWarned);
557-
var swap = encoding;
558-
encoding = offset;
559-
offset = length >>> 0;
560-
length = swap;
549+
// if someone is still calling the obsolete form of write(), tell them.
550+
// we don't want eg buf.write("foo", "utf8", 10) to silently turn into
551+
// buf.write("foo", "utf8"), so we can't ignore extra args
552+
throw new Error('Buffer.write(string, encoding, offset[, length]) ' +
553+
'is no longer supported');
561554
}
562555

563556
var remaining = this.length - offset;

test/parallel/test-buffer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ assert.equal(rangeBuffer.toString({toString: function() {
351351
// testing for smart defaults and ability to pass string values as offset
352352
var writeTest = new Buffer('abcdes');
353353
writeTest.write('n', 'ascii');
354-
writeTest.write('o', 'ascii', '1');
354+
writeTest.write('o', '1', 'ascii');
355355
writeTest.write('d', '2', 'ascii');
356356
writeTest.write('e', 3, 'ascii');
357-
writeTest.write('j', 'ascii', 4);
357+
writeTest.write('j', 4, 'ascii');
358358
assert.equal(writeTest.toString(), 'nodejs');
359359

360360
// ASCII slice test
@@ -895,7 +895,7 @@ assert.equal(0, Buffer('hello').slice(0, 0).length);
895895
assert.equal(buf[3], 0x63);
896896

897897
buf.fill(0xFF);
898-
written = buf.write('abcd', 'utf8', 1, 2); // legacy style
898+
written = buf.write('abcd', 1, 2, 'utf8');
899899
console.log(buf);
900900
assert.equal(written, 2);
901901
assert.equal(buf[0], 0xFF);

0 commit comments

Comments
 (0)