You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -437,8 +425,8 @@ These fields are of type `Number`:
437
425
*`versionNeededToExtract`
438
426
*`generalPurposeBitFlag`
439
427
*`compressionMethod`
440
-
*`lastModFileTime` (MS-DOS format, see [`getLastModDate()`](#getlastmoddate))
441
-
*`lastModFileDate` (MS-DOS format, see [`getLastModDate()`](#getlastmoddate))
428
+
*`lastModFileTime` (MS-DOS format, see [`getLastModDate()`](#getlastmoddateoptions))
429
+
*`lastModFileDate` (MS-DOS format, see [`getLastModDate()`](#getlastmoddateoptions))
442
430
*`crc32`
443
431
*`compressedSize`
444
432
*`uncompressedSize`
@@ -507,14 +495,46 @@ Prior to yauzl version 2.7.0, this field was erroneously documented as `comment`
507
495
For compatibility with any code that uses the field name `comment`,
508
496
yauzl creates an alias field named `comment` which is identical to `fileComment`.
509
497
510
-
#### getLastModDate()
498
+
#### getLastModDate([options])
499
+
500
+
Returns the modification time of the file as a JavaScript `Date` object.
501
+
The timezone situation is a mess; read on to learn more.
502
+
503
+
Due to the zip file specification having lackluster support for specifying timestamps natively,
504
+
there are several third-party extensions that add better support.
505
+
yauzl supports these encodings:
506
+
507
+
1. InfoZIP "universal timestamp" extended field (`0x5455` aka `"UT"`): signed 32-bit seconds since `1970-01-01 00:00:00Z`, which supports the years 1901-2038 (partially inclusive) with 1-second precision. The value is timezone agnostic, i.e. always UTC.
508
+
2. NTFS extended field (`0x000a`): 64-bit signed 100-nanoseconds since `1601-01-01 00:00:00Z`, which supports the approximate years 20,000BCE-20,000CE with precision rounded to 1-millisecond (due to the JavaScript `Date` type). The value is timezone agnostic, i.e. always UTC.
509
+
3. DOS `lastModFileDate` and `lastModFileTime`: supports the years 1980-2108 (inclusive) with 2-second precision. Timezone is interpreted either as the local timezone or UTC depending on the `timezone` option documented below.
511
510
512
-
Effectively implemented as the following. See [`dosDateTimeToDate()`](#dosdatetimetodatedate-time).
511
+
If both the InfoZIP "universal timestamp" and NTFS extended fields are found, yauzl uses one of them, but which one is unspecified.
512
+
If neither are found, yauzl falls back to the built-in DOS `lastModFileDate` and `lastModFileTime`.
513
+
Every possible bit pattern of every encoding can be represented by a JavaScript `Date` object,
514
+
meaning this function cannot fail (barring parameter validation), and will never return an `Invalid Date` object.
515
+
516
+
`options` may be omitted or `null`, and has the following defaults:
Set `forceDosFormat` to `true` (and do not set `timezone`) to enable pre-yauzl 3.2.0 behavior
526
+
where the InfoZIP "universal timestamp" and NTFS extended fields are ignored.
527
+
528
+
The `timezone` option is only used in the DOS fallback.
529
+
If `timezone` is omitted, `null` or `"local"`, the `lastModFileDate` and `lastModFileTime` are interpreted in the system's current timezone (using `new Date(year, ...)`).
530
+
If `timezone` is `"UTC"`, the interpretation is in UTC+00:00 (using `new Date(Date.UTC(year, ...))`).
531
+
532
+
The JavaScript `Date` object, has several inherent limitations surrounding timezones.
533
+
There is an ECMAScript proposal to add better timezone support to JavaScript called the `Temporal` API.
534
+
Last I checked, it was at stage 3. https://github.com/tc39/proposal-temporal
535
+
Once that new API is available and stable, better timezone handling should be possible here somehow.
536
+
If you notice that the new API has become widely available, please open a feature request against this library to add support for it.
537
+
518
538
#### isEncrypted()
519
539
520
540
Returns is this entry encrypted with "Traditional Encryption".
Copy file name to clipboardExpand all lines: test/test.js
+20-6Lines changed: 20 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,12 @@ var child_process = require("child_process");
9
9
varReadable=require("stream").Readable;
10
10
varWritable=require("stream").Writable;
11
11
12
-
// this is the date i made the example zip files and their content files,
13
-
// so this timestamp will be earlier than all the ones stored in these test zip files
14
-
// (and probably all future zip files).
15
-
// no timezone awareness, because that's how MS-DOS rolls.
12
+
// This is a month before I made the example zip files and their content files,
13
+
// so this timestamp will be earlier than all the ones stored in these test zip files unless otherwise noted.
16
14
varearliestTimestamp=newDate(2014,7,18,0,0,0,0);
17
15
16
+
if(Date.now()/1000>=2147483648)thrownewError("The year is 2038. The Epochalypse is uppon us. Signed 32-bit POSIX timestamps have collapsed. TODO: fix.");
17
+
18
18
varpend=newPend();
19
19
// 1 thing at a time for better determinism/reproducibility
0 commit comments