Skip to content

Commit 6ee7c2e

Browse files
committed
use Buffer.allocUnsafe
1 parent a6eb2c8 commit 6ee7c2e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", functi
2828
});
2929
// alternate apis for adding files:
3030
zipfile.addReadStream(process.stdin, "stdin.txt");
31-
zipfile.addBuffer(new Buffer("hello"), "hello.txt");
31+
zipfile.addBuffer(Buffer.from("hello"), "hello.txt");
3232
// call end() after all the files have been added
3333
zipfile.end();
3434
```

index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
277277
}
278278
}
279279

280-
var eocdrBuffer = Buffer.alloc(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
280+
var eocdrBuffer = Buffer.allocUnsafe(END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
281281
// end of central dir signature 4 bytes (0x06054b50)
282282
eocdrBuffer.writeUInt32LE(0x06054b50, 0);
283283
// number of this disk 2 bytes
@@ -301,7 +301,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
301301

302302
// ZIP64 format
303303
// ZIP64 End of Central Directory Record
304-
var zip64EocdrBuffer = Buffer.alloc(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
304+
var zip64EocdrBuffer = Buffer.allocUnsafe(ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE);
305305
// zip64 end of central dir signature 4 bytes (0x06064b50)
306306
zip64EocdrBuffer.writeUInt32LE(0x06064b50, 0);
307307
// size of zip64 end of central directory record 8 bytes
@@ -327,7 +327,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
327327

328328

329329
// ZIP64 End of Central Directory Locator
330-
var zip64EocdlBuffer = Buffer.alloc(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
330+
var zip64EocdlBuffer = Buffer.allocUnsafe(ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE);
331331
// zip64 end of central dir locator signature 4 bytes (0x07064b50)
332332
zip64EocdlBuffer.writeUInt32LE(0x07064b50, 0);
333333
// number of the disk with the start of the zip64 end of central directory 4 bytes
@@ -437,7 +437,7 @@ Entry.prototype.getLocalFileHeader = function() {
437437
uncompressedSize = this.uncompressedSize;
438438
}
439439

440-
var fixedSizeStuff = Buffer.alloc(LOCAL_FILE_HEADER_FIXED_SIZE);
440+
var fixedSizeStuff = Buffer.allocUnsafe(LOCAL_FILE_HEADER_FIXED_SIZE);
441441
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
442442
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
443443

@@ -476,10 +476,10 @@ var ZIP64_DATA_DESCRIPTOR_SIZE = 24;
476476
Entry.prototype.getDataDescriptor = function() {
477477
if (this.crcAndFileSizeKnown) {
478478
// the Mac Archive Utility requires this not be present unless we set general purpose bit 3
479-
return Buffer.alloc(0);
479+
return Buffer.allocUnsafe(0);
480480
}
481481
if (!this.useZip64Format()) {
482-
var buffer = Buffer.alloc(DATA_DESCRIPTOR_SIZE);
482+
var buffer = Buffer.allocUnsafe(DATA_DESCRIPTOR_SIZE);
483483
// optional signature (required according to Archive Utility)
484484
buffer.writeUInt32LE(0x08074b50, 0);
485485
// crc-32 4 bytes
@@ -491,7 +491,7 @@ Entry.prototype.getDataDescriptor = function() {
491491
return buffer;
492492
} else {
493493
// ZIP64 format
494-
var buffer = Buffer.alloc(ZIP64_DATA_DESCRIPTOR_SIZE);
494+
var buffer = Buffer.allocUnsafe(ZIP64_DATA_DESCRIPTOR_SIZE);
495495
// optional signature (unknown if anyone cares about this)
496496
buffer.writeUInt32LE(0x08074b50, 0);
497497
// crc-32 4 bytes
@@ -506,7 +506,7 @@ Entry.prototype.getDataDescriptor = function() {
506506
var CENTRAL_DIRECTORY_RECORD_FIXED_SIZE = 46;
507507
var ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE = 28;
508508
Entry.prototype.getCentralDirectoryRecord = function() {
509-
var fixedSizeStuff = Buffer.alloc(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
509+
var fixedSizeStuff = Buffer.allocUnsafe(CENTRAL_DIRECTORY_RECORD_FIXED_SIZE);
510510
var generalPurposeBitFlag = FILE_NAME_IS_UTF8;
511511
if (!this.crcAndFileSizeKnown) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES;
512512

@@ -522,7 +522,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
522522
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_ZIP64;
523523

524524
// ZIP64 extended information extra field
525-
zeiefBuffer = Buffer.alloc(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
525+
zeiefBuffer = Buffer.allocUnsafe(ZIP64_EXTENDED_INFORMATION_EXTRA_FIELD_SIZE);
526526
// 0x0001 2 bytes Tag for this "extra" block type
527527
zeiefBuffer.writeUInt16LE(0x0001, 0);
528528
// Size 2 bytes Size of this "extra" block
@@ -537,7 +537,7 @@ Entry.prototype.getCentralDirectoryRecord = function() {
537537
// (omit)
538538
} else {
539539
versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT_UTF8;
540-
zeiefBuffer = Buffer.alloc(0);
540+
zeiefBuffer = Buffer.allocUnsafe(0);
541541
}
542542

543543
// central file header signature 4 bytes (0x02014b50)

0 commit comments

Comments
 (0)