Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated Buffer.write(...) #5048

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

const binding = process.binding('buffer');
const internalUtil = require('internal/util');
const bindingObj = {};

exports.Buffer = Buffer;
Expand Down Expand Up @@ -533,10 +532,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#write(string);
if (offset === undefined) {
Expand All @@ -561,14 +556,9 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
encoding = length;
length = undefined;
}

// XXX legacy write(string, encoding, offset, length) - remove in v0.13
} else {
writeWarned = internalUtil.printDeprecationMessage(writeMsg, writeWarned);
var swap = encoding;
encoding = offset;
offset = length >>> 0;
length = swap;
throw new Error('Buffer.write(string, encoding, offset[, length]) ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically should be ``Buffer.write(string, encoding[, offset[, length]])'`, but I really don't care whether it's changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string, encoding fits into the current signature, so it's not deprecated. I made that mistake in the first grep :-).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChALkeR Sorry, not following.

'is no longer supported');
}

var remaining = this.length - offset;
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ assert.equal(rangeBuffer.toString({toString: function() {
// testing for smart defaults and ability to pass string values as offset
var writeTest = new Buffer('abcdes');
writeTest.write('n', 'ascii');
writeTest.write('o', 'ascii', '1');
writeTest.write('o', '1', 'ascii');
writeTest.write('d', '2', 'ascii');
writeTest.write('e', 3, 'ascii');
writeTest.write('j', 'ascii', 4);
writeTest.write('j', 4, 'ascii');
assert.equal(writeTest.toString(), 'nodejs');

// ASCII slice test
Expand Down Expand Up @@ -888,7 +888,7 @@ assert.equal(0, Buffer('hello').slice(0, 0).length);
assert.equal(buf[3], 0x63);

buf.fill(0xFF);
written = buf.write('abcd', 'utf8', 1, 2); // legacy style
written = buf.write('abcd', 1, 2, 'utf8');
console.log(buf);
assert.equal(written, 2);
assert.equal(buf[0], 0xFF);
Expand Down