Skip to content

Commit b0d4e6b

Browse files
committed
buffer alloc. closes archiverjs#35
1 parent a30ed8a commit b0d4e6b

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

lib/archivers/zip/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
module.exports = {
99
WORD: 4,
1010
DWORD: 8,
11-
EMPTY: new Buffer(0),
11+
EMPTY: Buffer.alloc(0),
1212

1313
SHORT: 2,
1414
SHORT_MASK: 0xffff,
1515
SHORT_SHIFT: 16,
16-
SHORT_ZERO: new Buffer(Array(2)),
16+
SHORT_ZERO: Buffer.alloc(Array(2)),
1717
LONG: 4,
18-
LONG_ZERO: new Buffer(Array(4)),
18+
LONG_ZERO: Buffer.alloc(Array(4)),
1919

2020
MIN_VERSION_INITIAL: 10,
2121
MIN_VERSION_DATA_DESCRIPTOR: 20,

lib/archivers/zip/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ util.fromDosTime = function(buf) {
4040
};
4141

4242
util.getEightBytes = function(v) {
43-
var buf = new Buffer(8);
43+
var buf = Buffer.alloc(8);
4444
buf.writeUInt32LE(v % 0x0100000000, 0);
4545
buf.writeUInt32LE((v / 0x0100000000) | 0, 4);
4646

4747
return buf;
4848
};
4949

5050
util.getShortBytes = function(v) {
51-
var buf = new Buffer(2);
51+
var buf = Buffer.alloc(2);
5252
buf.writeUInt16LE((v & 0xFFFF) >>> 0, 0);
5353

5454
return buf;
@@ -59,7 +59,7 @@ util.getShortBytesValue = function(buf, offset) {
5959
};
6060

6161
util.getLongBytes = function(v) {
62-
var buf = new Buffer(4);
62+
var buf = Buffer.alloc(4);
6363
buf.writeUInt32LE((v & 0xFFFFFFFF) >>> 0, 0);
6464

6565
return buf;

lib/archivers/zip/zip-archive-output-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ ZipArchiveOutputStream.prototype._writeCentralFileHeader = function(ae) {
313313
var extra = ae.getCentralDirectoryExtra();
314314

315315
if (gpb.usesUTF8ForNames()) {
316-
name = new Buffer(name);
317-
comment = new Buffer(comment);
316+
name = Buffer.alloc(name);
317+
comment = Buffer.alloc(comment);
318318
}
319319

320320
// name length
@@ -381,7 +381,7 @@ ZipArchiveOutputStream.prototype._writeLocalFileHeader = function(ae) {
381381
}
382382

383383
if (gpb.usesUTF8ForNames()) {
384-
name = new Buffer(name);
384+
name = Buffer.alloc(name);
385385
}
386386

387387
ae._offsets.file = this.offset;

lib/util/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ util.isStream = function(source) {
1616

1717
util.normalizeInputSource = function(source) {
1818
if (source === null) {
19-
return new Buffer(0);
19+
return Buffer.alloc(0);
2020
} else if (typeof source === 'string') {
21-
return new Buffer(source);
21+
return Buffer.alloc(source);
2222
} else if (util.isStream(source) && !source._readableState) {
2323
var normalized = new PassThrough();
2424
source.pipe(normalized);

test/helpers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var Readable = require('readable-stream').Readable;
77
var Writable = require('readable-stream').Writable;
88

99
function binaryBuffer(n) {
10-
var buffer = new Buffer(n);
10+
var buffer = Buffer.alloc(n);
1111

1212
for (var i = 0; i < n; i++) {
1313
buffer.writeUInt8(i&255, i);
@@ -21,7 +21,7 @@ module.exports.binaryBuffer = binaryBuffer;
2121
function BinaryStream(size, options) {
2222
Readable.call(this, options);
2323

24-
var buf = new Buffer(size);
24+
var buf = Buffer.alloc(size);
2525

2626
for (var i = 0; i < size; i++) {
2727
buf.writeUInt8(i&255, i);

0 commit comments

Comments
 (0)