@futpib/parser 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/allSettledStream.js +32 -14
- package/build/allSettledStream.test.js +32 -0
- package/build/androidPackage.d.ts +39 -0
- package/build/androidPackageParser.d.ts +17 -0
- package/build/androidPackageParser.js +183 -0
- package/build/{apkParser.test.js → androidPackageParser.test.js} +7 -7
- package/build/androidPackageUnparser.d.ts +4 -0
- package/build/androidPackageUnparser.js +90 -0
- package/build/androidPackageUnparser.test.js +26 -0
- package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
- package/build/arbitrarilySlicedAsyncInterable.js +3 -3
- package/build/arbitraryFileSystemEntry.js +1 -1
- package/build/arbitraryZip.d.ts +1 -1
- package/build/arbitraryZip.js +13 -19
- package/build/arbitraryZipPermissions.d.ts +1 -8
- package/build/arbitraryZipPermissions.js +1 -16
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arbitraryZipStream.js +3 -3
- package/build/arrayParser.d.ts +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayParser.test.js +4 -4
- package/build/arrayUnparser.d.ts +2 -0
- package/build/arrayUnparser.js +8 -0
- package/build/backsmali.d.ts +1 -0
- package/build/backsmali.js +22 -0
- package/build/bsonParser.js +6 -2
- package/build/bsonParser.test.js +2 -2
- package/build/{parserInvariant.d.ts → customInvariant.d.ts} +1 -1
- package/build/{parserInvariant.js → customInvariant.js} +1 -1
- package/build/dalvikBytecodeParser/formatParsers.d.ts +97 -0
- package/build/dalvikBytecodeParser/formatParsers.js +169 -0
- package/build/dalvikBytecodeParser.d.ts +107 -0
- package/build/dalvikBytecodeParser.js +836 -0
- package/build/dalvikExecutable.d.ts +158 -0
- package/build/dalvikExecutable.js +20 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
- package/build/dalvikExecutableParser/typeParsers.d.ts +10 -0
- package/build/dalvikExecutableParser/typeParsers.js +34 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +90 -0
- package/build/dalvikExecutableParser/typedNumbers.js +19 -0
- package/build/dalvikExecutableParser.d.ts +5 -0
- package/build/dalvikExecutableParser.js +1439 -0
- package/build/dalvikExecutableParser.test.js +70 -0
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +298 -0
- package/build/debugLogInputParser.d.ts +4 -0
- package/build/debugLogInputParser.js +16 -0
- package/build/debugLogParser.d.ts +1 -1
- package/build/debugLogParser.js +15 -4
- package/build/disjunctionParser.d.ts +2 -1
- package/build/disjunctionParser.js +4 -2
- package/build/elementParser.d.ts +2 -2
- package/build/elementParser.js +1 -1
- package/build/elementTerminatedArrayParser.d.ts +3 -0
- package/build/elementTerminatedArrayParser.js +18 -0
- package/build/elementTerminatedArrayParser.test.js +52 -0
- package/build/elementTerminatedSequenceArrayParser.d.ts +3 -0
- package/build/elementTerminatedSequenceArrayParser.js +32 -0
- package/build/elementTerminatedSequenceArrayParser.test.js +34 -0
- package/build/elementTerminatedSequenceParser.d.ts +3 -0
- package/build/elementTerminatedSequenceParser.js +27 -0
- package/build/elementTerminatedSequenceParser.test.js +34 -0
- package/build/endOfInputParser.d.ts +2 -2
- package/build/exactElementParser.d.ts +1 -1
- package/build/exactElementParser.js +10 -5
- package/build/exactSequenceParser.d.ts +2 -1
- package/build/exactSequenceParser.js +12 -2
- package/build/fetchCid.d.ts +1 -0
- package/build/fetchCid.js +107 -0
- package/build/fixedLengthSequenceParser.d.ts +1 -0
- package/build/fixedLengthSequenceParser.js +18 -1
- package/build/fixedLengthSequenceParser.test.js +41 -0
- package/build/hasExecutable.d.ts +1 -0
- package/build/hasExecutable.js +8 -0
- package/build/highResolutionTimer.d.ts +16 -0
- package/build/highResolutionTimer.js +42 -0
- package/build/index.d.ts +5 -2
- package/build/index.js +3 -0
- package/build/inputReader.d.ts +14 -3
- package/build/inputReader.js +43 -6
- package/build/inputReader.test.js +172 -7
- package/build/inputReaderState.d.ts +10 -0
- package/build/inputReaderState.js +16 -0
- package/build/inspect.d.ts +1 -0
- package/build/inspect.js +7 -0
- package/build/javaKeyStoreParser.d.ts +2 -0
- package/build/javaKeyStoreParser.js +67 -0
- package/build/javaKeyStoreParser.test.d.ts +1 -0
- package/build/javaKeyStoreParser.test.js +16 -0
- package/build/jsonParser.d.ts +2 -0
- package/build/jsonParser.js +13 -15
- package/build/jsonParser.test.js +2 -2
- package/build/leb128Parser.d.ts +7 -0
- package/build/leb128Parser.js +82 -0
- package/build/leb128Parser.test.d.ts +1 -0
- package/build/leb128Parser.test.js +107 -0
- package/build/listParser.d.ts +1 -1
- package/build/listParser.js +5 -5
- package/build/lookaheadParser.d.ts +2 -0
- package/build/lookaheadParser.js +14 -0
- package/build/{negativeLookahead.d.ts → negativeLookaheadParser.d.ts} +1 -1
- package/build/negativeLookaheadParser.js +24 -0
- package/build/negativeLookaheadParser.test.d.ts +1 -0
- package/build/negativeLookaheadParser.test.js +30 -0
- package/build/nonEmptyArrayParser.d.ts +2 -0
- package/build/nonEmptyArrayParser.js +32 -0
- package/build/nonEmptyArrayParser.test.d.ts +1 -0
- package/build/nonEmptyArrayParser.test.js +16 -0
- package/build/optionalParser.d.ts +1 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +13 -4
- package/build/parser.js +67 -32
- package/build/parser.test.js +94 -27
- package/build/parserAccessorParser.d.ts +1 -1
- package/build/parserAccessorParser.js +9 -1
- package/build/parserConsumedSequenceParser.d.ts +2 -0
- package/build/parserConsumedSequenceParser.js +22 -0
- package/build/parserContext.d.ts +20 -6
- package/build/parserContext.js +70 -40
- package/build/parserContext.test.js +34 -7
- package/build/parserCreatorCompose.d.ts +4 -3
- package/build/parserCreatorCompose.js +9 -3
- package/build/parserError.d.ts +6 -0
- package/build/parserError.js +6 -6
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.d.ts +35 -0
- package/build/parserInputCompanion.js +68 -0
- package/build/promiseCompose.d.ts +1 -1
- package/build/promiseCompose.js +12 -1
- package/build/promiseSettled.d.ts +1 -0
- package/build/promiseSettled.js +4 -0
- package/build/quantifierParser.d.ts +2 -0
- package/build/quantifierParser.js +17 -0
- package/build/separatedArrayParser.d.ts +2 -0
- package/build/separatedArrayParser.js +39 -0
- package/build/separatedArrayParser.test.d.ts +1 -0
- package/build/separatedArrayParser.test.js +21 -0
- package/build/sequenceBuffer.d.ts +13 -3
- package/build/sequenceBuffer.js +60 -8
- package/build/sequenceBuffer.test.js +59 -2
- package/build/sequenceTerminatedSequenceParser.d.ts +5 -0
- package/build/sequenceTerminatedSequenceParser.js +32 -0
- package/build/sequenceTerminatedSequenceParser.test.d.ts +1 -0
- package/build/sequenceTerminatedSequenceParser.test.js +37 -0
- package/build/sequenceUnparser.d.ts +2 -0
- package/build/sequenceUnparser.js +6 -0
- package/build/skipParser.d.ts +1 -1
- package/build/skipParser.js +4 -2
- package/build/skipToParser.d.ts +2 -0
- package/build/skipToParser.js +11 -0
- package/build/sliceBoundedParser.d.ts +2 -2
- package/build/sliceBoundedParser.js +8 -3
- package/build/sliceBoundedParser.test.js +37 -3
- package/build/smali.d.ts +1 -0
- package/build/smali.js +17 -0
- package/build/smaliParser.d.ts +12 -0
- package/build/smaliParser.js +656 -0
- package/build/smaliParser.test.d.ts +1 -0
- package/build/smaliParser.test.js +115 -0
- package/build/terminatedArrayParser.d.ts +4 -2
- package/build/terminatedArrayParser.js +82 -5
- package/build/terminatedArrayParser.test.d.ts +1 -0
- package/build/terminatedArrayParser.test.js +131 -0
- package/build/toAsyncIterable.d.ts +1 -0
- package/build/toAsyncIterable.js +7 -0
- package/build/toAsyncIterator.d.ts +1 -0
- package/build/toAsyncIterator.js +33 -0
- package/build/tupleParser.d.ts +4 -0
- package/build/tupleParser.js +1 -5
- package/build/uint8Array.d.ts +1 -0
- package/build/uint8Array.js +7 -0
- package/build/unionParser.d.ts +2 -1
- package/build/unionParser.js +27 -12
- package/build/unionParser.test.d.ts +1 -0
- package/build/unionParser.test.js +60 -0
- package/build/unparser.d.ts +8 -0
- package/build/unparser.js +104 -0
- package/build/unparser.test.d.ts +1 -0
- package/build/unparser.test.js +150 -0
- package/build/unparserContext.d.ts +31 -0
- package/build/unparserContext.js +74 -0
- package/build/unparserError.d.ts +9 -0
- package/build/unparserError.js +9 -0
- package/build/unparserImplementationInvariant.d.ts +2 -0
- package/build/unparserImplementationInvariant.js +5 -0
- package/build/unparserOutputCompanion.d.ts +15 -0
- package/build/unparserOutputCompanion.js +13 -0
- package/build/zip.d.ts +9 -17
- package/build/zipParser.d.ts +20 -12
- package/build/zipParser.js +83 -71
- package/build/zipParser.test.js +2 -7
- package/build/zipUnparser.d.ts +8 -0
- package/build/zipUnparser.js +200 -0
- package/build/zipUnparser.test.d.ts +1 -0
- package/build/zipUnparser.test.js +80 -0
- package/package.json +26 -8
- package/src/allSettledStream.test.ts +40 -0
- package/src/allSettledStream.ts +47 -15
- package/src/androidPackage.ts +48 -0
- package/src/{apkParser.test.ts → androidPackageParser.test.ts} +7 -8
- package/src/androidPackageParser.test.ts.md +271 -0
- package/src/androidPackageParser.test.ts.snap +0 -0
- package/src/androidPackageParser.ts +440 -0
- package/src/androidPackageUnparser.test.ts +36 -0
- package/src/androidPackageUnparser.ts +120 -0
- package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
- package/src/arbitraryFileSystemEntry.ts +2 -4
- package/src/arbitraryZip.ts +20 -27
- package/src/arbitraryZipPermissions.ts +0 -25
- package/src/arbitraryZipStream.ts +4 -4
- package/src/arrayParser.test.ts +4 -4
- package/src/arrayParser.ts +3 -2
- package/src/arrayUnparser.ts +13 -0
- package/src/backsmali.ts +30 -0
- package/src/bsonParser.test.ts +2 -2
- package/src/bsonParser.ts +16 -5
- package/src/{parserInvariant.ts → customInvariant.ts} +2 -2
- package/src/dalvikBytecodeParser/formatParsers.ts +421 -0
- package/src/dalvikBytecodeParser.ts +2074 -0
- package/src/dalvikExecutable.ts +220 -0
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
- package/src/dalvikExecutableParser/typeParsers.ts +65 -0
- package/src/dalvikExecutableParser/typedNumbers.ts +57 -0
- package/src/dalvikExecutableParser.test.ts +89 -0
- package/src/dalvikExecutableParser.test.ts.md +634 -0
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +2768 -0
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +346 -0
- package/src/debugLogInputParser.ts +28 -0
- package/src/debugLogParser.ts +20 -4
- package/src/disjunctionParser.ts +10 -5
- package/src/elementParser.ts +3 -3
- package/src/elementTerminatedArrayParser.test.ts +99 -0
- package/src/elementTerminatedArrayParser.ts +31 -0
- package/src/elementTerminatedSequenceArrayParser.test.ts +54 -0
- package/src/elementTerminatedSequenceArrayParser.ts +52 -0
- package/src/elementTerminatedSequenceParser.test.ts +54 -0
- package/src/elementTerminatedSequenceParser.ts +43 -0
- package/src/endOfInputParser.ts +4 -4
- package/src/exactElementParser.ts +18 -12
- package/src/exactSequenceParser.ts +24 -3
- package/src/fetchCid.ts +125 -0
- package/src/fixedLengthSequenceParser.test.ts +77 -0
- package/src/fixedLengthSequenceParser.ts +28 -1
- package/src/hasExecutable.ts +11 -0
- package/src/highResolutionTimer.ts +49 -0
- package/src/index.ts +15 -2
- package/src/inputReader.test.ts +216 -7
- package/src/inputReader.ts +80 -5
- package/src/inputReaderState.ts +33 -0
- package/src/inspect.ts +9 -0
- package/src/javaKeyStore.ts +0 -0
- package/src/javaKeyStoreParser.test.ts +22 -0
- package/src/javaKeyStoreParser.test.ts.md +103 -0
- package/src/javaKeyStoreParser.test.ts.snap +0 -0
- package/src/javaKeyStoreParser.ts +136 -0
- package/src/jsonParser.test.ts +2 -2
- package/src/jsonParser.ts +23 -34
- package/src/leb128Parser.test.ts +171 -0
- package/src/leb128Parser.ts +125 -0
- package/src/listParser.ts +6 -6
- package/src/lookaheadParser.ts +19 -0
- package/src/negativeLookaheadParser.test.ts +53 -0
- package/src/negativeLookaheadParser.ts +36 -0
- package/src/nonEmptyArrayParser.test.ts +20 -0
- package/src/nonEmptyArrayParser.ts +44 -0
- package/src/optionalParser.ts +4 -3
- package/src/parser.test.ts +148 -27
- package/src/parser.test.ts.md +21 -21
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +153 -49
- package/src/parserAccessorParser.ts +12 -2
- package/src/parserConsumedSequenceParser.ts +29 -0
- package/src/parserContext.test.ts +38 -7
- package/src/parserContext.ts +127 -51
- package/src/parserCreatorCompose.ts +25 -7
- package/src/parserError.ts +9 -6
- package/src/parserImplementationInvariant.ts +2 -2
- package/src/parserInputCompanion.ts +102 -0
- package/src/promiseCompose.ts +17 -3
- package/src/promiseSettled.ts +6 -0
- package/src/quantifierParser.ts +25 -0
- package/src/separatedArrayParser.test.ts +34 -0
- package/src/separatedArrayParser.ts +55 -0
- package/src/sequenceBuffer.test.ts +72 -2
- package/src/sequenceBuffer.ts +93 -7
- package/src/sequenceTerminatedSequenceParser.test.ts +60 -0
- package/src/sequenceTerminatedSequenceParser.ts +62 -0
- package/src/sequenceUnparser.ts +9 -0
- package/src/skipParser.ts +7 -5
- package/src/skipToParser.ts +16 -0
- package/src/sliceBoundedParser.test.ts +45 -3
- package/src/sliceBoundedParser.ts +21 -3
- package/src/smali.ts +24 -0
- package/src/smaliParser.test.ts +132 -0
- package/src/smaliParser.test.ts.md +2320 -0
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +1166 -0
- package/src/terminatedArrayParser.test.ts +258 -0
- package/src/terminatedArrayParser.ts +111 -6
- package/src/toAsyncIterable.ts +7 -0
- package/src/toAsyncIterator.ts +48 -0
- package/src/tupleParser.ts +8 -5
- package/src/uint8Array.ts +10 -0
- package/src/unionParser.test.ts +79 -0
- package/src/unionParser.ts +44 -16
- package/src/unparser.test.ts +221 -0
- package/src/unparser.ts +209 -0
- package/src/unparserContext.ts +127 -0
- package/src/unparserError.ts +12 -0
- package/src/unparserImplementationInvariant.ts +6 -0
- package/src/unparserOutputCompanion.ts +24 -0
- package/src/zip.ts +10 -22
- package/src/zipParser.test.ts +2 -8
- package/src/zipParser.ts +223 -146
- package/src/zipUnparser.test.ts +119 -0
- package/src/zipUnparser.ts +300 -0
- package/build/apk.d.ts +0 -13
- package/build/apkParser.d.ts +0 -3
- package/build/apkParser.js +0 -135
- package/build/arbitraryDosDate.d.ts +0 -2
- package/build/arbitraryDosDate.js +0 -8
- package/build/arbitraryZipEntry.d.ts +0 -3
- package/build/arbitraryZipEntry.js +0 -26
- package/build/createDisjunctionParser.d.ts +0 -2
- package/build/createDisjunctionParser.js +0 -47
- package/build/createExactParser.d.ts +0 -2
- package/build/createExactParser.js +0 -12
- package/build/createSequentialUnionParser.d.ts +0 -2
- package/build/createSequentialUnionParser.js +0 -69
- package/build/fixedLengthChunkParser.d.ts +0 -2
- package/build/fixedLengthChunkParser.js +0 -12
- package/build/fixedLengthParser.d.ts +0 -2
- package/build/fixedLengthParser.js +0 -12
- package/build/inputChunkBuffer.d.ts +0 -15
- package/build/inputChunkBuffer.js +0 -40
- package/build/inputChunkBuffer.test.js +0 -34
- package/build/inputCompanion.d.ts +0 -18
- package/build/inputCompanion.js +0 -28
- package/build/invariantDefined.d.ts +0 -1
- package/build/invariantDefined.js +0 -5
- package/build/invariantIdentity.d.ts +0 -3
- package/build/invariantIdentity.js +0 -5
- package/build/jsonParser2.d.ts +0 -3
- package/build/jsonParser2.js +0 -52
- package/build/jsonParser2.test.js +0 -22
- package/build/negativeLookahead.js +0 -20
- package/build/parserCompose.d.ts +0 -3
- package/build/parserCompose.js +0 -7
- package/build/parserImplementationInvariantInvariant.d.ts +0 -3
- package/build/parserImplementationInvariantInvariant.js +0 -15
- package/build/promiseFish.d.ts +0 -1
- package/build/promiseFish.js +0 -3
- package/build/sequenceParser.d.ts +0 -3
- package/build/sequenceParser.js +0 -10
- package/build/terminatedSequenceParser.d.ts +0 -2
- package/build/terminatedSequenceParser.js +0 -24
- package/build/zipEntry.d.ts +0 -28
- package/build/zipFile.d.ts +0 -32
- package/build/zipFileEntry.d.ts +0 -6
- package/src/apk.ts +0 -16
- package/src/apkParser.test.ts.md +0 -268
- package/src/apkParser.test.ts.snap +0 -0
- package/src/apkParser.ts +0 -327
- package/src/inputCompanion.ts +0 -43
- package/src/invariantDefined.ts +0 -6
- package/src/invariantIdentity.ts +0 -8
- package/src/negativeLookahead.ts +0 -26
- /package/build/{apk.js → androidPackage.js} +0 -0
- /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.d.ts → androidPackageUnparser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.js → dalvikExecutableParser.test.d.ts} +0 -0
- /package/build/{inputChunkBuffer.test.d.ts → dalvikExecutableParserAgainstSmaliParser.test.d.ts} +0 -0
- /package/build/{jsonParser2.test.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.d.ts → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.js → elementTerminatedSequenceParser.test.d.ts} +0 -0
- /package/build/{zipEntry.js → fixedLengthSequenceParser.test.d.ts} +0 -0
- /package/build/{zipFile.js → javaKeyStore.d.ts} +0 -0
- /package/build/{zipFileEntry.js → javaKeyStore.js} +0 -0
package/src/zipParser.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { pipeline } from 'node:stream/promises';
|
|
4
|
+
import invariant from 'invariant';
|
|
5
|
+
import { createArrayParser } from './arrayParser.js';
|
|
6
|
+
import { createExactSequenceParser } from './exactSequenceParser.js';
|
|
7
|
+
import { type Parser, setParserName } from './parser.js';
|
|
8
|
+
import { createTupleParser } from './tupleParser.js';
|
|
9
|
+
import { promiseCompose } from './promiseCompose.js';
|
|
10
|
+
import { createFixedLengthSequenceParser } from './fixedLengthSequenceParser.js';
|
|
11
|
+
import { createOptionalParser } from './optionalParser.js';
|
|
12
|
+
import { parserCreatorCompose } from './parserCreatorCompose.js';
|
|
13
|
+
import {
|
|
14
|
+
type Zip,
|
|
15
|
+
type ZipCompression,
|
|
16
|
+
type ZipDirectoryEntry,
|
|
17
|
+
type ZipEntry,
|
|
18
|
+
type ZipFileEntry,
|
|
19
|
+
} from './zip.js';
|
|
20
|
+
import { uint8ArrayAsyncIterableToUint8Array } from './uint8Array.js';
|
|
21
|
+
import { createNegativeLookaheadParser } from './negativeLookaheadParser.js';
|
|
22
|
+
import { createSequenceTerminatedSequenceParser } from './sequenceTerminatedSequenceParser.js';
|
|
14
23
|
|
|
15
24
|
// https://pkwaredownloads.blob.core.windows.net/pem/APPNOTE.txt
|
|
16
25
|
|
|
@@ -34,12 +43,12 @@ const dosDateTimeParser: Parser<Date, Uint8Array> = promiseCompose(
|
|
|
34
43
|
uint16LEParser,
|
|
35
44
|
]),
|
|
36
45
|
([ time, date ]) => new Date(Date.UTC(
|
|
37
|
-
1980 + ((date >> 9) &
|
|
38
|
-
((date >> 5) &
|
|
39
|
-
date &
|
|
40
|
-
(time >> 11) &
|
|
41
|
-
(time >> 5) &
|
|
42
|
-
(time &
|
|
46
|
+
1980 + ((date >> 9) & 0x7F),
|
|
47
|
+
((date >> 5) & 0xF) - 1,
|
|
48
|
+
date & 0x1F,
|
|
49
|
+
(time >> 11) & 0x1F,
|
|
50
|
+
(time >> 5) & 0x3F,
|
|
51
|
+
(time & 0x1F) * 2,
|
|
43
52
|
)),
|
|
44
53
|
);
|
|
45
54
|
|
|
@@ -58,21 +67,23 @@ const zipCompressionMethodParser: Parser<ZipCompression, Uint8Array> = promiseCo
|
|
|
58
67
|
},
|
|
59
68
|
);
|
|
60
69
|
|
|
61
|
-
type ZipLocalFileHeader = {
|
|
70
|
+
export type ZipLocalFileHeader = {
|
|
62
71
|
versionNeededToExtract: number;
|
|
63
72
|
generalPurposeBitFlag: number;
|
|
64
73
|
compressionMethod: ZipCompression;
|
|
65
|
-
|
|
74
|
+
lastModifiedFile: Date;
|
|
66
75
|
crc32: number;
|
|
67
76
|
compressedSize: number;
|
|
68
77
|
uncompressedSize: number;
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
filePath: string;
|
|
71
80
|
extraField: Uint8Array;
|
|
72
81
|
};
|
|
73
82
|
|
|
83
|
+
const zipLocalFileHeaderSignatureParser = createExactSequenceParser<Uint8Array>(Buffer.from('504b0304', 'hex'));
|
|
84
|
+
|
|
74
85
|
const zipLocalFileHeaderParser_ = createTupleParser([
|
|
75
|
-
|
|
86
|
+
zipLocalFileHeaderSignatureParser,
|
|
76
87
|
uint16LEParser,
|
|
77
88
|
uint16LEParser,
|
|
78
89
|
zipCompressionMethodParser,
|
|
@@ -86,10 +97,10 @@ const zipLocalFileHeaderParser_ = createTupleParser([
|
|
|
86
97
|
uint16LEParser,
|
|
87
98
|
]),
|
|
88
99
|
([
|
|
89
|
-
|
|
100
|
+
filePathLength,
|
|
90
101
|
extraFieldLength,
|
|
91
102
|
]) => createTupleParser([
|
|
92
|
-
createFixedLengthSequenceParser(
|
|
103
|
+
createFixedLengthSequenceParser(filePathLength),
|
|
93
104
|
createFixedLengthSequenceParser(extraFieldLength),
|
|
94
105
|
]),
|
|
95
106
|
)(),
|
|
@@ -104,20 +115,20 @@ const zipLocalFileHeaderParser: Parser<ZipLocalFileHeader, Uint8Array> = promise
|
|
|
104
115
|
versionNeededToExtract,
|
|
105
116
|
generalPurposeBitFlag,
|
|
106
117
|
compressionMethod,
|
|
107
|
-
|
|
118
|
+
lastModifiedFile,
|
|
108
119
|
crc32,
|
|
109
120
|
compressedSize,
|
|
110
121
|
uncompressedSize,
|
|
111
|
-
[
|
|
122
|
+
[ filePath, extraField ],
|
|
112
123
|
]) => ({
|
|
113
124
|
versionNeededToExtract,
|
|
114
125
|
generalPurposeBitFlag,
|
|
115
126
|
compressionMethod,
|
|
116
|
-
|
|
127
|
+
lastModifiedFile,
|
|
117
128
|
crc32,
|
|
118
129
|
compressedSize,
|
|
119
130
|
uncompressedSize,
|
|
120
|
-
|
|
131
|
+
filePath: Buffer.from(filePath).toString('utf8'),
|
|
121
132
|
extraField,
|
|
122
133
|
}),
|
|
123
134
|
);
|
|
@@ -126,31 +137,84 @@ const zipEncryptionHeaderParser: Parser<unknown, Uint8Array> = async parserConte
|
|
|
126
137
|
parserContext.invariant(false, 'Not implemented');
|
|
127
138
|
};
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
type ZipDataDescriptor = {
|
|
141
|
+
crc32: number;
|
|
142
|
+
compressedSize: number;
|
|
143
|
+
uncompressedSize: number;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const zipDataDescriptorSignature: Uint8Array = Buffer.from('504b0708', 'hex');
|
|
147
|
+
const zipDataDescriptorSignatureParser = createExactSequenceParser<Uint8Array>(
|
|
148
|
+
zipDataDescriptorSignature
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const zipDataDescriptorParser: Parser<ZipDataDescriptor, Uint8Array> = promiseCompose(
|
|
152
|
+
createTupleParser([
|
|
153
|
+
createNegativeLookaheadParser(
|
|
154
|
+
zipLocalFileHeaderSignatureParser,
|
|
155
|
+
),
|
|
156
|
+
// FIXME: optional in spec
|
|
157
|
+
//createOptionalParser(zipDataDescriptorSignatureParser),
|
|
158
|
+
zipDataDescriptorSignatureParser,
|
|
159
|
+
uint32LEParser,
|
|
160
|
+
uint32LEParser,
|
|
161
|
+
uint32LEParser,
|
|
162
|
+
]),
|
|
163
|
+
([
|
|
164
|
+
_notZipLocalFileHeaderSignature,
|
|
165
|
+
_zipDataDescriptorSignature,
|
|
166
|
+
crc32,
|
|
167
|
+
compressedSize,
|
|
168
|
+
uncompressedSize,
|
|
169
|
+
]) => ({
|
|
170
|
+
crc32,
|
|
171
|
+
compressedSize,
|
|
172
|
+
uncompressedSize,
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
137
175
|
|
|
138
|
-
|
|
176
|
+
setParserName(zipDataDescriptorParser, 'zipDataDescriptorParser');
|
|
177
|
+
|
|
178
|
+
export type ZipLocalFile = {
|
|
139
179
|
zipLocalFileHeader: ZipLocalFileHeader;
|
|
140
180
|
zipEncryptionHeader: unknown;
|
|
141
181
|
compressedData: Uint8Array;
|
|
142
|
-
zipDataDescriptor:
|
|
182
|
+
zipDataDescriptor: undefined | ZipDataDescriptor;
|
|
143
183
|
};
|
|
144
184
|
|
|
145
185
|
export const zipLocalFileParser: Parser<ZipLocalFile, Uint8Array> = promiseCompose(
|
|
146
186
|
parserCreatorCompose(
|
|
147
187
|
() => zipLocalFileHeaderParser,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
188
|
+
zipLocalFileHeader => {
|
|
189
|
+
const sizeInDataDescriptor = Boolean(
|
|
190
|
+
zipLocalFileHeader.generalPurposeBitFlag & 0b0000_0000_0000_1000
|
|
191
|
+
&& zipLocalFileHeader.crc32 === 0
|
|
192
|
+
&& zipLocalFileHeader.compressedSize === 0
|
|
193
|
+
&& zipLocalFileHeader.uncompressedSize === 0
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
return createTupleParser([
|
|
197
|
+
async () => zipLocalFileHeader,
|
|
198
|
+
createOptionalParser(zipEncryptionHeaderParser),
|
|
199
|
+
(
|
|
200
|
+
sizeInDataDescriptor
|
|
201
|
+
? createSequenceTerminatedSequenceParser(
|
|
202
|
+
zipDataDescriptorSignature,
|
|
203
|
+
{
|
|
204
|
+
consumeTerminator: false,
|
|
205
|
+
},
|
|
206
|
+
)
|
|
207
|
+
: createFixedLengthSequenceParser(zipLocalFileHeader.compressedSize)
|
|
208
|
+
),
|
|
209
|
+
(
|
|
210
|
+
sizeInDataDescriptor
|
|
211
|
+
? (<T>(parser: T): T => parser)
|
|
212
|
+
: createOptionalParser
|
|
213
|
+
)(
|
|
214
|
+
zipDataDescriptorParser
|
|
215
|
+
),
|
|
216
|
+
]);
|
|
217
|
+
},
|
|
154
218
|
)(),
|
|
155
219
|
([
|
|
156
220
|
zipLocalFileHeader,
|
|
@@ -191,83 +255,117 @@ const zipVersionMadeByParser: Parser<ZipVersionMadeBy, Uint8Array> = promiseComp
|
|
|
191
255
|
}),
|
|
192
256
|
);
|
|
193
257
|
|
|
194
|
-
type
|
|
258
|
+
type ZipExternalFileAttributes = {
|
|
259
|
+
directory: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const dosExternalFileAttributesParser: Parser<ZipExternalFileAttributes, Uint8Array> = promiseCompose(
|
|
263
|
+
uint32LEParser,
|
|
264
|
+
externalFileAttributes => ({
|
|
265
|
+
directory: (externalFileAttributes & 0b0001_0000) !== 0,
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
const unixExternalFileAttributesParser: Parser<ZipExternalFileAttributes, Uint8Array> = promiseCompose(
|
|
270
|
+
uint32LEParser,
|
|
271
|
+
externalFileAttributes => ({
|
|
272
|
+
directory: (externalFileAttributes & (0b0100_0000_0000_0000 << 16)) !== 0,
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const createExternalFileAttributesParser = (hostSystem: number) => promiseCompose(
|
|
277
|
+
hostSystem === 0 ? dosExternalFileAttributesParser : unixExternalFileAttributesParser,
|
|
278
|
+
externalFileAttributes => externalFileAttributes,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
export type ZipCentralDirectoryHeader = {
|
|
195
282
|
versionMadeBy: ZipVersionMadeBy;
|
|
196
283
|
versionNeededToExtract: number;
|
|
197
284
|
generalPurposeBitFlag: number;
|
|
198
285
|
compressionMethod: ZipCompression;
|
|
199
|
-
|
|
286
|
+
lastModifiedFile: Date;
|
|
200
287
|
crc32: number;
|
|
201
288
|
compressedSize: number;
|
|
202
289
|
uncompressedSize: number;
|
|
203
290
|
diskNumberStart: number;
|
|
204
291
|
internalFileAttributes: number;
|
|
205
|
-
externalFileAttributes:
|
|
292
|
+
externalFileAttributes: ZipExternalFileAttributes;
|
|
206
293
|
relativeOffsetOfLocalHeader: number;
|
|
207
294
|
|
|
208
|
-
|
|
295
|
+
filePath: string;
|
|
209
296
|
extraField: Uint8Array;
|
|
210
297
|
fileComment: string;
|
|
211
298
|
};
|
|
212
299
|
|
|
213
|
-
const zipCentralDirectoryHeaderParser_ =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
300
|
+
const zipCentralDirectoryHeaderParser_ = parserCreatorCompose(
|
|
301
|
+
() => createTupleParser([
|
|
302
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('504b0102', 'hex')),
|
|
303
|
+
zipVersionMadeByParser,
|
|
304
|
+
]),
|
|
305
|
+
([
|
|
306
|
+
_centralDirectoryHeaderSignature,
|
|
307
|
+
versionMadeBy,
|
|
308
|
+
]) => createTupleParser([
|
|
309
|
+
async () => versionMadeBy,
|
|
310
|
+
uint16LEParser,
|
|
311
|
+
uint16LEParser,
|
|
312
|
+
zipCompressionMethodParser,
|
|
313
|
+
dosDateTimeParser,
|
|
314
|
+
uint32LEParser,
|
|
315
|
+
uint32LEParser,
|
|
316
|
+
uint32LEParser,
|
|
317
|
+
parserCreatorCompose(
|
|
318
|
+
() => createTupleParser([
|
|
319
|
+
uint16LEParser,
|
|
320
|
+
uint16LEParser,
|
|
321
|
+
uint16LEParser,
|
|
322
|
+
|
|
323
|
+
uint16LEParser,
|
|
324
|
+
uint16LEParser,
|
|
325
|
+
|
|
326
|
+
createExternalFileAttributesParser(versionMadeBy.hostSystem),
|
|
327
|
+
uint32LEParser,
|
|
328
|
+
]),
|
|
329
|
+
([
|
|
330
|
+
filePathLength,
|
|
331
|
+
extraFieldLength,
|
|
332
|
+
fileCommentLength,
|
|
333
|
+
|
|
334
|
+
diskNumberStart,
|
|
335
|
+
internalFileAttributes,
|
|
336
|
+
|
|
337
|
+
externalFileAttributes,
|
|
338
|
+
relativeOffsetOfLocalHeader,
|
|
339
|
+
]) => createTupleParser([
|
|
340
|
+
createFixedLengthSequenceParser(filePathLength),
|
|
341
|
+
createFixedLengthSequenceParser(extraFieldLength),
|
|
342
|
+
createFixedLengthSequenceParser(fileCommentLength),
|
|
343
|
+
|
|
344
|
+
async () => diskNumberStart,
|
|
345
|
+
async () => internalFileAttributes,
|
|
346
|
+
|
|
347
|
+
async () => externalFileAttributes,
|
|
348
|
+
async () => relativeOffsetOfLocalHeader,
|
|
349
|
+
]),
|
|
350
|
+
)(),
|
|
351
|
+
]),
|
|
352
|
+
)();
|
|
254
353
|
|
|
255
354
|
setParserName(zipCentralDirectoryHeaderParser_, 'centralDirectoryHeaderParser_');
|
|
256
355
|
|
|
257
356
|
export const zipCentralDirectoryHeaderParser: Parser<ZipCentralDirectoryHeader, Uint8Array> = promiseCompose(
|
|
258
357
|
zipCentralDirectoryHeaderParser_,
|
|
259
358
|
([
|
|
260
|
-
_centralDirectoryHeaderSignature,
|
|
261
359
|
versionMadeBy,
|
|
262
360
|
versionNeededToExtract,
|
|
263
361
|
generalPurposeBitFlag,
|
|
264
362
|
compressionMethod,
|
|
265
|
-
|
|
363
|
+
lastModifiedFile,
|
|
266
364
|
crc32,
|
|
267
365
|
compressedSize,
|
|
268
366
|
uncompressedSize,
|
|
269
367
|
[
|
|
270
|
-
|
|
368
|
+
filePath,
|
|
271
369
|
extraField,
|
|
272
370
|
fileComment,
|
|
273
371
|
|
|
@@ -281,7 +379,7 @@ export const zipCentralDirectoryHeaderParser: Parser<ZipCentralDirectoryHeader,
|
|
|
281
379
|
versionNeededToExtract,
|
|
282
380
|
generalPurposeBitFlag,
|
|
283
381
|
compressionMethod,
|
|
284
|
-
|
|
382
|
+
lastModifiedFile,
|
|
285
383
|
crc32,
|
|
286
384
|
compressedSize,
|
|
287
385
|
uncompressedSize,
|
|
@@ -289,7 +387,7 @@ export const zipCentralDirectoryHeaderParser: Parser<ZipCentralDirectoryHeader,
|
|
|
289
387
|
internalFileAttributes,
|
|
290
388
|
externalFileAttributes,
|
|
291
389
|
relativeOffsetOfLocalHeader,
|
|
292
|
-
|
|
390
|
+
filePath: Buffer.from(filePath).toString('utf8'),
|
|
293
391
|
extraField,
|
|
294
392
|
fileComment: Buffer.from(fileComment).toString('utf8'),
|
|
295
393
|
}),
|
|
@@ -311,14 +409,14 @@ const zipFileCommentParser: Parser<string, Uint8Array> = promiseCompose(
|
|
|
311
409
|
uint8Array => Buffer.from(uint8Array).toString('utf8'),
|
|
312
410
|
);
|
|
313
411
|
|
|
314
|
-
type ZipEndOfCentralDirectoryRecord = {
|
|
315
|
-
numberOfThisDisk: number
|
|
316
|
-
numberOfTheDiskWithTheStartOfTheCentralDirectory: number
|
|
317
|
-
totalNumberOfEntriesInTheCentralDirectoryOnThisDisk: number
|
|
318
|
-
totalNumberOfEntriesInTheCentralDirectory: number
|
|
319
|
-
sizeOfTheCentralDirectory: number
|
|
320
|
-
offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber: number
|
|
321
|
-
zipFileComment: string
|
|
412
|
+
export type ZipEndOfCentralDirectoryRecord = {
|
|
413
|
+
numberOfThisDisk: number;
|
|
414
|
+
numberOfTheDiskWithTheStartOfTheCentralDirectory: number;
|
|
415
|
+
totalNumberOfEntriesInTheCentralDirectoryOnThisDisk: number;
|
|
416
|
+
totalNumberOfEntriesInTheCentralDirectory: number;
|
|
417
|
+
sizeOfTheCentralDirectory: number;
|
|
418
|
+
offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber: number;
|
|
419
|
+
zipFileComment: string;
|
|
322
420
|
};
|
|
323
421
|
|
|
324
422
|
const zipEndOfCentralDirectoryRecordParser_ = createTupleParser([
|
|
@@ -332,7 +430,7 @@ const zipEndOfCentralDirectoryRecordParser_ = createTupleParser([
|
|
|
332
430
|
zipFileCommentParser,
|
|
333
431
|
]);
|
|
334
432
|
|
|
335
|
-
setParserName(zipEndOfCentralDirectoryRecordParser_, '
|
|
433
|
+
setParserName(zipEndOfCentralDirectoryRecordParser_, 'zipEndOfCentralDirectoryRecordParser_');
|
|
336
434
|
|
|
337
435
|
export const zipEndOfCentralDirectoryRecordParser: Parser<ZipEndOfCentralDirectoryRecord, Uint8Array> = promiseCompose(
|
|
338
436
|
zipEndOfCentralDirectoryRecordParser_,
|
|
@@ -356,6 +454,8 @@ export const zipEndOfCentralDirectoryRecordParser: Parser<ZipEndOfCentralDirecto
|
|
|
356
454
|
}),
|
|
357
455
|
);
|
|
358
456
|
|
|
457
|
+
setParserName(zipEndOfCentralDirectoryRecordParser, 'zipEndOfCentralDirectoryRecordParser');
|
|
458
|
+
|
|
359
459
|
const zipParser_ = createTupleParser([
|
|
360
460
|
createArrayParser(zipLocalFileParser),
|
|
361
461
|
createOptionalParser(zipArchiveDecryptionHeaderParser),
|
|
@@ -372,10 +472,10 @@ export async function zipEntriesFromZipSegments({
|
|
|
372
472
|
zipLocalFiles,
|
|
373
473
|
zipCentralDirectoryHeaders,
|
|
374
474
|
}: {
|
|
375
|
-
zipLocalFiles: ZipLocalFile[]
|
|
376
|
-
zipCentralDirectoryHeaders: ZipCentralDirectoryHeader[]
|
|
475
|
+
zipLocalFiles: ZipLocalFile[];
|
|
476
|
+
zipCentralDirectoryHeaders: ZipCentralDirectoryHeader[];
|
|
377
477
|
}) {
|
|
378
|
-
const decompressPromises: Promise<void
|
|
478
|
+
const decompressPromises: Array<Promise<void>> = [];
|
|
379
479
|
|
|
380
480
|
const entries: ZipEntry[] = await Promise.all(zipLocalFiles.map(async (zipLocalFile, index) => {
|
|
381
481
|
const {
|
|
@@ -389,41 +489,24 @@ export async function zipEntriesFromZipSegments({
|
|
|
389
489
|
|
|
390
490
|
invariant(centralDirectoryHeader, 'Central directory header not found for local file %s', index);
|
|
391
491
|
|
|
392
|
-
let isDosDirectory = false;
|
|
393
|
-
let permissions: ZipPermissions = {
|
|
394
|
-
type: 'unix',
|
|
395
|
-
unixPermissions: 0,
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
if (centralDirectoryHeader.versionMadeBy.hostSystem === 0) {
|
|
399
|
-
isDosDirectory = (centralDirectoryHeader.externalFileAttributes & 0b00010000) !== 0;
|
|
400
|
-
permissions = {
|
|
401
|
-
type: 'dos',
|
|
402
|
-
dosPermissions: centralDirectoryHeader.externalFileAttributes & 0b00111111,
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (centralDirectoryHeader.versionMadeBy.hostSystem === 3) {
|
|
407
|
-
permissions = {
|
|
408
|
-
type: 'unix',
|
|
409
|
-
unixPermissions: (centralDirectoryHeader.externalFileAttributes >> 16) & 0b111111111,
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
492
|
const commonFields: Omit<ZipFileEntry | ZipDirectoryEntry, 'type'> = {
|
|
414
|
-
path: zipLocalFileHeader.
|
|
493
|
+
path: zipLocalFileHeader.filePath,
|
|
415
494
|
comment: centralDirectoryHeader.fileComment,
|
|
416
|
-
date: zipLocalFileHeader.
|
|
417
|
-
|
|
495
|
+
date: zipLocalFileHeader.lastModifiedFile,
|
|
496
|
+
hostSystem: centralDirectoryHeader.versionMadeBy.hostSystem === 0 ? 'dos' : 'unix',
|
|
497
|
+
attributes: centralDirectoryHeader.externalFileAttributes,
|
|
418
498
|
};
|
|
419
499
|
|
|
420
|
-
const isDirectory =
|
|
500
|
+
const isDirectory = (
|
|
501
|
+
centralDirectoryHeader.externalFileAttributes.directory
|
|
502
|
+
|| commonFields.path.endsWith('/')
|
|
503
|
+
);
|
|
421
504
|
|
|
422
505
|
if (isDirectory) {
|
|
423
506
|
return {
|
|
424
507
|
...commonFields,
|
|
425
508
|
type: 'directory',
|
|
426
|
-
path: commonFields.path.
|
|
509
|
+
path: commonFields.path.replace(/\/$/, ''),
|
|
427
510
|
};
|
|
428
511
|
}
|
|
429
512
|
|
|
@@ -434,18 +517,12 @@ export async function zipEntriesFromZipSegments({
|
|
|
434
517
|
compression: zipLocalFileHeader.compressionMethod,
|
|
435
518
|
};
|
|
436
519
|
|
|
437
|
-
if (fileEntry.content.length && fileEntry.compression === 'deflate') {
|
|
438
|
-
const
|
|
520
|
+
if (fileEntry.content.length > 0 && fileEntry.compression === 'deflate') {
|
|
521
|
+
const inflate = zlib.createInflateRaw();
|
|
439
522
|
const input = Readable.from(Buffer.from(compressedData));
|
|
440
523
|
const [ _, buffer ] = await Promise.all([
|
|
441
|
-
pipeline(input,
|
|
442
|
-
(
|
|
443
|
-
const chunks: Buffer[] = [];
|
|
444
|
-
for await (const chunk of deflate) {
|
|
445
|
-
chunks.push(chunk);
|
|
446
|
-
}
|
|
447
|
-
return Buffer.concat(chunks);
|
|
448
|
-
})(),
|
|
524
|
+
pipeline(input, inflate),
|
|
525
|
+
uint8ArrayAsyncIterableToUint8Array(inflate),
|
|
449
526
|
]);
|
|
450
527
|
|
|
451
528
|
fileEntry.content = Uint8Array.from(buffer);
|
|
@@ -465,10 +542,10 @@ export async function zipFromZipSegments({
|
|
|
465
542
|
|
|
466
543
|
zipEndOfCentralDirectoryRecord,
|
|
467
544
|
}: {
|
|
468
|
-
zipLocalFiles: ZipLocalFile[]
|
|
469
|
-
zipCentralDirectoryHeaders: ZipCentralDirectoryHeader[]
|
|
545
|
+
zipLocalFiles: ZipLocalFile[];
|
|
546
|
+
zipCentralDirectoryHeaders: ZipCentralDirectoryHeader[];
|
|
470
547
|
|
|
471
|
-
zipEndOfCentralDirectoryRecord: ZipEndOfCentralDirectoryRecord
|
|
548
|
+
zipEndOfCentralDirectoryRecord: ZipEndOfCentralDirectoryRecord;
|
|
472
549
|
}) {
|
|
473
550
|
const entries = await zipEntriesFromZipSegments({
|
|
474
551
|
zipLocalFiles,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { fc, testProp } from '@fast-check/ava';
|
|
2
|
+
import { temporaryFile } from 'tempy';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
import fsPromises from 'node:fs/promises';
|
|
5
|
+
import { runUnparser } from './unparser.js';
|
|
6
|
+
import { createZipUnparser } from './zipUnparser.js';
|
|
7
|
+
import { uint8ArrayUnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
8
|
+
import { runParser } from './parser.js';
|
|
9
|
+
import { zipParser } from './zipParser.js';
|
|
10
|
+
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
11
|
+
import { arbitraryZip } from './arbitraryZip.js';
|
|
12
|
+
import { hasExecutable } from './hasExecutable.js';
|
|
13
|
+
|
|
14
|
+
const hasZipinfoPromise = hasExecutable('zipinfo');
|
|
15
|
+
const has7zPromise = hasExecutable('7z');
|
|
16
|
+
|
|
17
|
+
async function zipinfo(zipFilePath: string) {
|
|
18
|
+
const { stdout } = await execa('zipinfo', [
|
|
19
|
+
'-v',
|
|
20
|
+
zipFilePath,
|
|
21
|
+
], {
|
|
22
|
+
reject: false,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
isEmptyZipfile: stdout.endsWith('Empty zipfile.'),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function _7zList(zipFilePath: string) {
|
|
31
|
+
const { stdout } = await execa('7z', [
|
|
32
|
+
'l',
|
|
33
|
+
zipFilePath,
|
|
34
|
+
], {
|
|
35
|
+
reject: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (/Errors: \d+$/.test(stdout)) {
|
|
39
|
+
throw new Error(`7z reports errors: ${stdout}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
isEmptyZipfile: false, // TODO
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
testProp(
|
|
48
|
+
'zip',
|
|
49
|
+
[
|
|
50
|
+
arbitraryZip,
|
|
51
|
+
fc.record({
|
|
52
|
+
dataDescriptor: fc.boolean(),
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
async (t, zip, options) => {
|
|
56
|
+
const zipUnparser = createZipUnparser(options);
|
|
57
|
+
|
|
58
|
+
{
|
|
59
|
+
const zipStream = runUnparser(zipUnparser, zip, uint8ArrayUnparserOutputCompanion);
|
|
60
|
+
|
|
61
|
+
await fsPromises.writeFile('/tmp/zip.zip', zipStream);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const actualStream = runUnparser(zipUnparser, zip, uint8ArrayUnparserOutputCompanion);
|
|
65
|
+
const actual = await runParser(zipParser, actualStream, uint8ArrayParserInputCompanion);
|
|
66
|
+
|
|
67
|
+
t.deepEqual(actual, zip);
|
|
68
|
+
|
|
69
|
+
const hasZipinfo = await hasZipinfoPromise;
|
|
70
|
+
const has7z = await has7zPromise;
|
|
71
|
+
|
|
72
|
+
if (!hasZipinfo && !has7z) {
|
|
73
|
+
t.pass('no zipinfo or 7z, skipping zipfile check');
|
|
74
|
+
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const temporaryFilePath = temporaryFile({
|
|
79
|
+
extension: 'zip',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const zipStream = runUnparser(zipUnparser, zip, uint8ArrayUnparserOutputCompanion);
|
|
83
|
+
|
|
84
|
+
await fsPromises.writeFile(temporaryFilePath, zipStream);
|
|
85
|
+
|
|
86
|
+
if (has7z) {
|
|
87
|
+
const {
|
|
88
|
+
isEmptyZipfile,
|
|
89
|
+
} = await _7zList(temporaryFilePath);
|
|
90
|
+
|
|
91
|
+
if (isEmptyZipfile) {
|
|
92
|
+
t.deepEqual(
|
|
93
|
+
actual.entries,
|
|
94
|
+
[],
|
|
95
|
+
'7z reports the zipfile as empty, but it has entries',
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (hasZipinfo) {
|
|
101
|
+
const {
|
|
102
|
+
isEmptyZipfile,
|
|
103
|
+
} = await zipinfo(temporaryFilePath);
|
|
104
|
+
|
|
105
|
+
if (isEmptyZipfile) {
|
|
106
|
+
t.deepEqual(
|
|
107
|
+
actual.entries.filter(entry => entry.type === 'file'),
|
|
108
|
+
[],
|
|
109
|
+
'zipinfo reports the zipfile as empty, but it has file entries',
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
await fsPromises.unlink(temporaryFilePath);
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
verbose: true,
|
|
118
|
+
},
|
|
119
|
+
);
|