@@ -17,7 +17,6 @@ function ZipFile() {
17
17
this . ended = false ; // .end() sets this
18
18
this . allDone = false ; // set when we've written the last bytes
19
19
this . forceZip64Eocd = false ; // configurable in .end()
20
- this . comment = "" ;
21
20
}
22
21
23
22
ZipFile . prototype . addFile = function ( realPath , metadataPath , options ) {
@@ -119,6 +118,7 @@ ZipFile.prototype.end = function(options, finalSizeCallback) {
119
118
this . ended = true ;
120
119
this . finalSizeCallback = finalSizeCallback ;
121
120
this . forceZip64Eocd = ! ! options . forceZip64Format ;
121
+ this . comment = Buffer . from ( options . comment || "" , "utf-8" ) ;
122
122
pumpEntries ( this ) ;
123
123
} ;
124
124
@@ -241,7 +241,7 @@ function calculateFinalSize(self) {
241
241
// use zip64 end of central directory stuff
242
242
endOfCentralDirectorySize += ZIP64_END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIZE ;
243
243
}
244
- endOfCentralDirectorySize += END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + Buffer . byteLength ( self . comment , "utf-8" ) ;
244
+ endOfCentralDirectorySize += END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + self . comment . length ;
245
245
return pretendOutputCursor + centralDirectorySize + endOfCentralDirectorySize ;
246
246
}
247
247
@@ -278,8 +278,7 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
278
278
}
279
279
}
280
280
281
- var comment = Buffer . from ( self . comment , "utf-8" )
282
- var eocdrBuffer = Buffer . alloc ( END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + comment . length ) ;
281
+ var eocdrBuffer = Buffer . alloc ( END_OF_CENTRAL_DIRECTORY_RECORD_SIZE + self . comment . length ) ;
283
282
// end of central dir signature 4 bytes (0x06054b50)
284
283
eocdrBuffer . writeUInt32LE ( 0x06054b50 , 0 ) ;
285
284
// number of this disk 2 bytes
@@ -295,9 +294,9 @@ function getEndOfCentralDirectoryRecord(self, actuallyJustTellMeHowLongItWouldBe
295
294
// offset of start of central directory with respect to the starting disk number 4 bytes
296
295
eocdrBuffer . writeUInt32LE ( normalOffsetOfStartOfCentralDirectory , 16 ) ;
297
296
// .ZIP file comment length 2 bytes
298
- eocdrBuffer . writeUInt16LE ( comment . length , 20 ) ;
297
+ eocdrBuffer . writeUInt16LE ( self . comment . length , 20 ) ;
299
298
// .ZIP file comment (variable size)
300
- comment . copy ( eocdrBuffer , 22 ) ;
299
+ self . comment . copy ( eocdrBuffer , 22 ) ;
301
300
302
301
if ( ! needZip64Format ) return eocdrBuffer ;
303
302
0 commit comments