@@ -257,7 +257,10 @@ function Entry(metadataPath, isDirectory, options) {
257
257
this . uncompressedSize = 0 ;
258
258
this . compressedSize = 0 ;
259
259
} else {
260
- this . uncompressedSize = null ; // unknown
260
+ // unknown
261
+ this . crc32 = null ;
262
+ this . uncompressedSize = null ;
263
+ this . compressedSize = null ;
261
264
if ( options . size != null ) this . uncompressedSize = options . size ;
262
265
}
263
266
if ( isDirectory ) {
@@ -294,17 +297,31 @@ var VERSION_MADE_BY_INFO_ZIP = 0x031e;
294
297
var FILE_NAME_IS_UTF8 = 1 << 11 ;
295
298
var UNKNOWN_CRC32_AND_FILE_SIZES = 1 << 3 ;
296
299
Entry . prototype . getLocalFileHeader = function ( ) {
300
+ var crcAndFileSizeKnown = this . crc32 != null &&
301
+ this . uncompressedSize != null &&
302
+ this . compressedSize != null ;
303
+ var crc32 = 0 ;
304
+ var compressedSize = 0 ;
305
+ var uncompressedSize = 0 ;
306
+ if ( crcAndFileSizeKnown ) {
307
+ crc32 = this . crc32 ;
308
+ compressedSize = this . compressedSize ;
309
+ uncompressedSize = this . uncompressedSize ;
310
+ }
311
+
297
312
var fixedSizeStuff = new Buffer ( LOCAL_FILE_HEADER_FIXED_SIZE ) ;
298
- var generalPurposeBitFlag = UNKNOWN_CRC32_AND_FILE_SIZES | FILE_NAME_IS_UTF8 ;
313
+ var generalPurposeBitFlag = FILE_NAME_IS_UTF8 ;
314
+ if ( ! crcAndFileSizeKnown ) generalPurposeBitFlag |= UNKNOWN_CRC32_AND_FILE_SIZES ;
315
+
299
316
fixedSizeStuff . writeUInt32LE ( 0x04034b50 , 0 ) ; // local file header signature 4 bytes (0x04034b50)
300
317
fixedSizeStuff . writeUInt16LE ( VERSION_NEEDED_TO_EXTRACT , 4 ) ; // version needed to extract 2 bytes
301
318
fixedSizeStuff . writeUInt16LE ( generalPurposeBitFlag , 6 ) ; // general purpose bit flag 2 bytes
302
319
fixedSizeStuff . writeUInt16LE ( this . getCompressionMethod ( ) , 8 ) ; // compression method 2 bytes
303
320
fixedSizeStuff . writeUInt16LE ( this . lastModFileTime , 10 ) ; // last mod file time 2 bytes
304
321
fixedSizeStuff . writeUInt16LE ( this . lastModFileDate , 12 ) ; // last mod file date 2 bytes
305
- fixedSizeStuff . writeUInt32LE ( 0 , 14 ) ; // crc-32 4 bytes
306
- fixedSizeStuff . writeUInt32LE ( 0 , 18 ) ; // compressed size 4 bytes
307
- fixedSizeStuff . writeUInt32LE ( 0 , 22 ) ; // uncompressed size 4 bytes
322
+ fixedSizeStuff . writeUInt32LE ( crc32 , 14 ) ; // crc-32 4 bytes
323
+ fixedSizeStuff . writeUInt32LE ( compressedSize , 18 ) ; // compressed size 4 bytes
324
+ fixedSizeStuff . writeUInt32LE ( uncompressedSize , 22 ) ; // uncompressed size 4 bytes
308
325
fixedSizeStuff . writeUInt16LE ( this . utf8FileName . length , 26 ) ; // file name length 2 bytes
309
326
fixedSizeStuff . writeUInt16LE ( 0 , 28 ) ; // extra field length 2 bytes
310
327
return Buffer . concat ( [
0 commit comments