Skip to content

Commit 9e99dfd

Browse files
committed
Remove all usage of new Buffer(); use Buffer.from()/Buffer.alloc()
Fixes protobufjs#99
1 parent 4144951 commit 9e99dfd

File tree

13 files changed

+16
-16
lines changed

13 files changed

+16
-16
lines changed

src/bytebuffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var ByteBuffer = function(capacity, littleEndian, noAssert) {
3232
* @type {!Buffer}
3333
* @expose
3434
*/
35-
this.buffer = capacity === 0 ? EMPTY_BUFFER : new Buffer(capacity);
35+
this.buffer = capacity === 0 ? EMPTY_BUFFER : Buffer.alloc(capacity);
3636
//? } else {
3737

3838
/**

src/encodings/base64.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ByteBufferPrototype.toBase64 = function(begin, end) {
4646
*/
4747
ByteBuffer.fromBase64 = function(str, littleEndian) {
4848
//? if (NODE) {
49-
return ByteBuffer.wrap(new Buffer(str, "base64"), littleEndian);
49+
return ByteBuffer.wrap(Buffer.from(str, "base64"), littleEndian);
5050
//? } else {
5151
if (typeof str !== 'string')
5252
throw TypeError("str");

src/encodings/binary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ByteBufferPrototype.toBinary = function(begin, end) {
4949
*/
5050
ByteBuffer.fromBinary = function(str, littleEndian) {
5151
//? if (NODE) {
52-
return ByteBuffer.wrap(new Buffer(str, "binary"), littleEndian);
52+
return ByteBuffer.wrap(Buffer.from(str, "binary"), littleEndian);
5353
//? } else {
5454
if (typeof str !== 'string')
5555
throw TypeError("str");

src/encodings/hex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ByteBuffer.fromHex = function(str, littleEndian, noAssert) {
5151
}
5252
//? if (NODE) {
5353
var bb = new ByteBuffer(0, littleEndian, true);
54-
bb.buffer = new Buffer(str, "hex");
54+
bb.buffer = Buffer.from(str, "hex");
5555
bb.limit = bb.buffer.length;
5656
//? } else {
5757
var k = str.length,

src/encodings/utf8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) {
5252
throw TypeError("Illegal str: Not a string");
5353
//? if (NODE) {
5454
var bb = new ByteBuffer(0, littleEndian, noAssert);
55-
bb.buffer = new Buffer(str, "utf8");
55+
bb.buffer = Buffer.from(str, "utf8");
5656
bb.limit = bb.buffer.length;
5757
//? } else {
5858
var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert),

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @type {!Buffer}
66
* @inner
77
*/
8-
var EMPTY_BUFFER = new Buffer(0);
8+
var EMPTY_BUFFER = Buffer.alloc(0);
99
//? } else {
1010

1111
/**

src/methods/clone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ByteBufferPrototype.clone = function(copy) {
99
var bb = new ByteBuffer(0, this.littleEndian, this.noAssert);
1010
if (copy) {
1111
//? if (NODE) {
12-
var buffer = new Buffer(this.buffer.length);
12+
var buffer = Buffer.alloc(this.buffer.length);
1313
this.buffer.copy(buffer);
1414
bb.buffer = buffer;
1515
//? } else {

src/methods/compact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ByteBufferPrototype.compact = function(begin, end) {
2626
return this;
2727
}
2828
//? if (NODE) {
29-
var buffer = new Buffer(len);
29+
var buffer = Buffer.alloc(len);
3030
this.buffer.copy(buffer, 0, begin, end);
3131
this.buffer = buffer;
3232
//? } else if (DATAVIEW) {

src/methods/prepend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ByteBufferPrototype.prepend = function(source, encoding, offset) {
3333
var diff = len - offset;
3434
if (diff > 0) { // Not enough space before offset, so resize + move
3535
//? if (NODE) {
36-
var buffer = new Buffer(this.buffer.length + diff);
36+
var buffer = Buffer.alloc(this.buffer.length + diff);
3737
this.buffer.copy(buffer, len, offset, this.buffer.length);
3838
this.buffer = buffer;
3939
//? } else if (DATAVIEW) {

src/methods/resize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ByteBufferPrototype.resize = function(capacity) {
1515
}
1616
//? if (NODE) {
1717
if (this.buffer.length < capacity) {
18-
var buffer = new Buffer(capacity);
18+
var buffer = Buffer.alloc(capacity);
1919
this.buffer.copy(buffer);
2020
this.buffer = buffer;
2121
}

0 commit comments

Comments
 (0)