@futpib/parser 1.0.2 → 1.0.3
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/.github/copilot-instructions.md +149 -0
- package/.github/workflows/copilot-setup-steps.yml +18 -0
- package/.github/workflows/main.yml +29 -8
- package/.yarn/releases/yarn-4.9.4.cjs +942 -0
- package/.yarnrc.yml +1 -1
- package/build/allSettledStream.js +1 -1
- package/build/allSettledStream.test.js +2 -2
- package/build/androidPackageParser.d.ts +1 -1
- package/build/androidPackageParser.js +5 -3
- package/build/androidPackageParser.test.js +7 -7
- package/build/androidPackageUnparser.d.ts +2 -2
- package/build/androidPackageUnparser.js +18 -14
- package/build/androidPackageUnparser.test.js +7 -7
- package/build/arbitrarilySlicedAsyncInterator.js +2 -1
- package/build/arbitraryDalvikBytecode.d.ts +4 -0
- package/build/arbitraryDalvikBytecode.js +640 -0
- package/build/arbitraryDalvikExecutable.d.ts +3 -0
- package/build/arbitraryDalvikExecutable.js +282 -0
- package/build/arbitraryDosDateTime.js +1 -0
- package/build/arbitraryZipStream.js +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayUnparser.d.ts +1 -1
- package/build/backsmali.d.ts +3 -1
- package/build/backsmali.js +31 -3
- package/build/customInvariant.d.ts +2 -1
- package/build/customInvariant.js +4 -6
- package/build/dalvikBytecodeParser/formatParsers.d.ts +76 -2
- package/build/dalvikBytecodeParser/formatParsers.js +146 -11
- package/build/dalvikBytecodeParser/formatSizes.d.ts +34 -0
- package/build/dalvikBytecodeParser/formatSizes.js +34 -0
- package/build/dalvikBytecodeParser/operationFormats.d.ts +225 -0
- package/build/dalvikBytecodeParser/operationFormats.js +225 -0
- package/build/dalvikBytecodeParser.d.ts +1105 -5
- package/build/dalvikBytecodeParser.js +658 -205
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +152 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +225 -0
- package/build/dalvikBytecodeUnparser.d.ts +3 -0
- package/build/dalvikBytecodeUnparser.js +642 -0
- package/build/dalvikBytecodeUnparser.test.d.ts +1 -0
- package/build/dalvikBytecodeUnparser.test.js +25 -0
- package/build/dalvikExecutable.d.ts +65 -8
- package/build/dalvikExecutable.js +36 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +1 -1
- package/build/dalvikExecutableParser/stringSyntaxParser.js +17 -17
- package/build/dalvikExecutableParser/typeParsers.d.ts +2 -1
- package/build/dalvikExecutableParser/typeParsers.js +16 -11
- package/build/dalvikExecutableParser/typedNumbers.d.ts +85 -69
- package/build/dalvikExecutableParser/typedNumbers.js +0 -1
- package/build/dalvikExecutableParser.d.ts +2 -2
- package/build/dalvikExecutableParser.js +655 -337
- package/build/dalvikExecutableParser.test.js +24 -22
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +223 -246
- package/build/dalvikExecutableUnparser/annotationUnparsers.d.ts +14 -0
- package/build/dalvikExecutableUnparser/annotationUnparsers.js +97 -0
- package/build/dalvikExecutableUnparser/poolBuilders.d.ts +49 -0
- package/build/dalvikExecutableUnparser/poolBuilders.js +140 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +4 -0
- package/build/dalvikExecutableUnparser/poolScanners.js +220 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +25 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +581 -0
- package/build/dalvikExecutableUnparser/utils.d.ts +10 -0
- package/build/dalvikExecutableUnparser/utils.js +108 -0
- package/build/dalvikExecutableUnparser.d.ts +4 -0
- package/build/dalvikExecutableUnparser.js +406 -0
- package/build/dalvikExecutableUnparser.test.d.ts +1 -0
- package/build/dalvikExecutableUnparser.test.js +31 -0
- package/build/debugLogInputParser.js +1 -1
- package/build/disjunctionParser.d.ts +2 -2
- package/build/disjunctionParser.js +2 -2
- package/build/elementTerminatedArrayParser.d.ts +2 -2
- package/build/elementTerminatedArrayParser.js +1 -1
- package/build/elementTerminatedArrayParser.test.js +5 -5
- package/build/elementTerminatedSequenceArrayParser.d.ts +2 -2
- package/build/elementTerminatedSequenceArrayParser.js +1 -1
- package/build/elementTerminatedSequenceArrayParser.test.js +2 -2
- package/build/elementTerminatedSequenceParser.d.ts +2 -2
- package/build/elementTerminatedSequenceParser.js +1 -1
- package/build/elementTerminatedSequenceParser.test.js +2 -2
- package/build/endOfInputParser.d.ts +1 -1
- package/build/exactElementSwitchParser.d.ts +3 -0
- package/build/exactElementSwitchParser.js +22 -0
- package/build/fetchCid.js +2 -6
- package/build/fetchCid.test.d.ts +1 -0
- package/build/fetchCid.test.js +16 -0
- package/build/fixedLengthSequenceParser.test.js +2 -2
- package/build/hasExecutable.js +2 -2
- package/build/highResolutionTimer.js +1 -1
- package/build/inputReader.d.ts +1 -1
- package/build/inputReader.test.js +33 -45
- package/build/javaKeyStoreParser.test.js +6 -6
- package/build/jsonParser.js +8 -8
- package/build/lazyMessageError.d.ts +48 -0
- package/build/lazyMessageError.js +53 -0
- package/build/lazyMessageError.test.d.ts +1 -0
- package/build/lazyMessageError.test.js +15 -0
- package/build/leb128Parser.d.ts +1 -1
- package/build/leb128Parser.js +10 -10
- package/build/leb128Parser.test.js +7 -7
- package/build/negativeLookaheadParser.js +2 -2
- package/build/negativeLookaheadParser.test.js +4 -4
- package/build/noStackCaptureOverheadError.d.ts +4 -0
- package/build/noStackCaptureOverheadError.js +9 -0
- package/build/noStackCaptureOverheadError.test.d.ts +1 -0
- package/build/noStackCaptureOverheadError.test.js +15 -0
- package/build/nonEmptyArrayParser.js +2 -2
- package/build/nonEmptyArrayParser.test.js +2 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +2 -1
- package/build/parser.js +23 -8
- package/build/parser.test.js +78 -29
- package/build/parserConsumedSequenceParser.d.ts +1 -1
- package/build/parserConsumedSequenceParser.js +2 -2
- package/build/parserContext.d.ts +8 -6
- package/build/parserContext.js +60 -33
- package/build/parserContext.test.js +7 -3
- package/build/parserError.d.ts +603 -44
- package/build/parserError.js +98 -53
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.js +2 -2
- package/build/promiseCompose.js +1 -2
- package/build/separatedArrayParser.js +2 -2
- package/build/separatedNonEmptyArrayParser.d.ts +2 -0
- package/build/separatedNonEmptyArrayParser.js +40 -0
- package/build/separatedNonEmptyArrayParser.test.d.ts +1 -0
- package/build/separatedNonEmptyArrayParser.test.js +66 -0
- package/build/sequenceBuffer.js +1 -1
- package/build/sequenceTerminatedSequenceParser.d.ts +2 -2
- package/build/sequenceTerminatedSequenceParser.js +3 -3
- package/build/sequenceTerminatedSequenceParser.test.js +1 -1
- package/build/sequenceUnparser.d.ts +1 -1
- package/build/skipToParser.d.ts +1 -1
- package/build/skipToParser.js +2 -2
- package/build/sliceBoundedParser.test.js +4 -9
- package/build/smali.d.ts +1 -1
- package/build/smali.js +6 -2
- package/build/smaliParser.d.ts +62 -6
- package/build/smaliParser.js +1721 -296
- package/build/smaliParser.test.js +338 -43
- package/build/stringFromAsyncIterable.d.ts +1 -0
- package/build/stringFromAsyncIterable.js +7 -0
- package/build/terminatedArrayParser.js +4 -4
- package/build/terminatedArrayParser.test.js +7 -7
- package/build/toAsyncIterator.js +4 -4
- package/build/unionParser.d.ts +1 -1
- package/build/unionParser.js +2 -2
- package/build/unionParser.test.js +3 -3
- package/build/unparser.d.ts +3 -3
- package/build/unparser.js +6 -4
- package/build/unparser.test.js +7 -19
- package/build/unparserContext.d.ts +2 -2
- package/build/unparserContext.js +2 -3
- package/build/unparserError.d.ts +2 -1
- package/build/unparserError.js +2 -1
- package/build/unparserImplementationInvariant.d.ts +1 -1
- package/build/unparserOutputCompanion.d.ts +1 -1
- package/build/unparserOutputCompanion.js +1 -1
- package/build/zipParser.js +1 -1
- package/build/zipUnparser.d.ts +3 -3
- package/build/zipUnparser.js +9 -19
- package/build/zipUnparser.test.js +1 -1
- package/package.json +19 -26
- package/src/allSettledStream.test.ts +2 -2
- package/src/allSettledStream.ts +3 -3
- package/src/androidPackageParser.test.ts +17 -19
- package/src/androidPackageParser.ts +129 -171
- package/src/androidPackageUnparser.test.ts +19 -21
- package/src/androidPackageUnparser.ts +23 -17
- package/src/arbitrarilySlicedAsyncInterable.ts +1 -1
- package/src/arbitrarilySlicedAsyncInterator.ts +4 -4
- package/src/arbitraryDalvikBytecode.ts +992 -0
- package/src/arbitraryDalvikExecutable.ts +434 -0
- package/src/arbitraryDosDateTime.ts +1 -0
- package/src/arbitraryZipStream.ts +1 -1
- package/src/arrayParser.ts +2 -2
- package/src/arrayUnparser.ts +2 -2
- package/src/backsmali.ts +48 -4
- package/src/bsonParser.test.ts +12 -14
- package/src/customInvariant.ts +8 -12
- package/src/dalvikBytecodeParser/formatParsers.ts +376 -17
- package/src/dalvikBytecodeParser/formatSizes.ts +35 -0
- package/src/dalvikBytecodeParser/operationFormats.ts +226 -0
- package/src/dalvikBytecodeParser.ts +1042 -243
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +442 -0
- package/src/dalvikBytecodeUnparser.test.ts +44 -0
- package/src/dalvikBytecodeUnparser.ts +758 -0
- package/src/dalvikExecutable.ts +110 -48
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +33 -33
- package/src/dalvikExecutableParser/typeParsers.ts +23 -14
- package/src/dalvikExecutableParser/typedNumbers.ts +19 -19
- package/src/dalvikExecutableParser.test.ts +60 -60
- package/src/dalvikExecutableParser.test.ts.md +6 -6
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +911 -434
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +256 -239
- package/src/dalvikExecutableUnparser/annotationUnparsers.ts +135 -0
- package/src/dalvikExecutableUnparser/poolBuilders.ts +189 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +297 -0
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +683 -0
- package/src/dalvikExecutableUnparser/utils.ts +149 -0
- package/src/dalvikExecutableUnparser.test.ts +57 -0
- package/src/dalvikExecutableUnparser.ts +581 -0
- package/src/debugLogInputParser.ts +1 -1
- package/src/disjunctionParser.ts +5 -5
- package/src/elementTerminatedArrayParser.test.ts +8 -8
- package/src/elementTerminatedArrayParser.ts +2 -2
- package/src/elementTerminatedSequenceArrayParser.test.ts +4 -6
- package/src/elementTerminatedSequenceArrayParser.ts +2 -2
- package/src/elementTerminatedSequenceParser.test.ts +4 -6
- package/src/elementTerminatedSequenceParser.ts +2 -2
- package/src/endOfInputParser.ts +1 -1
- package/src/exactElementSwitchParser.ts +41 -0
- package/src/fetchCid.test.ts +20 -0
- package/src/fetchCid.ts +3 -7
- package/src/fixedLengthSequenceParser.test.ts +10 -12
- package/src/hasExecutable.ts +2 -2
- package/src/highResolutionTimer.ts +1 -1
- package/src/inputReader.test.ts +39 -52
- package/src/inputReader.ts +2 -4
- package/src/inputReaderState.ts +1 -1
- package/src/inspect.ts +1 -1
- package/src/javaKeyStoreParser.test.ts +12 -14
- package/src/javaKeyStoreParser.ts +2 -6
- package/src/jsonParser.test.ts +2 -4
- package/src/jsonParser.ts +34 -38
- package/src/lazyMessageError.test.ts +21 -0
- package/src/lazyMessageError.ts +88 -0
- package/src/leb128Parser.test.ts +25 -23
- package/src/leb128Parser.ts +19 -19
- package/src/negativeLookaheadParser.test.ts +7 -11
- package/src/negativeLookaheadParser.ts +2 -2
- package/src/noStackCaptureOverheadError.test.ts +17 -0
- package/src/noStackCaptureOverheadError.ts +12 -0
- package/src/nonEmptyArrayParser.test.ts +3 -2
- package/src/nonEmptyArrayParser.ts +2 -2
- package/src/optionalParser.ts +2 -2
- package/src/parser.test.ts +96 -43
- package/src/parser.test.ts.md +13 -6
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +35 -12
- package/src/parserAccessorParser.ts +1 -1
- package/src/parserConsumedSequenceParser.ts +3 -3
- package/src/parserContext.test.ts +7 -3
- package/src/parserContext.ts +82 -48
- package/src/parserError.ts +143 -63
- package/src/parserImplementationInvariant.ts +3 -3
- package/src/parserInputCompanion.ts +2 -2
- package/src/promiseCompose.ts +2 -2
- package/src/separatedArrayParser.ts +3 -3
- package/src/separatedNonEmptyArrayParser.test.ts +117 -0
- package/src/separatedNonEmptyArrayParser.ts +61 -0
- package/src/sequenceBuffer.test.ts +9 -9
- package/src/sequenceBuffer.ts +4 -4
- package/src/sequenceTerminatedSequenceParser.test.ts +3 -5
- package/src/sequenceTerminatedSequenceParser.ts +4 -4
- package/src/sequenceUnparser.ts +2 -2
- package/src/skipToParser.ts +2 -2
- package/src/sliceBoundedParser.test.ts +4 -12
- package/src/sliceBoundedParser.ts +2 -2
- package/src/smali.ts +8 -3
- package/src/smaliParser.test.ts +377 -66
- package/src/smaliParser.test.ts.md +1635 -48
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +2751 -569
- package/src/stringFromAsyncIterable.ts +9 -0
- package/src/terminatedArrayParser.test.ts +11 -11
- package/src/terminatedArrayParser.ts +5 -7
- package/src/toAsyncIterator.ts +8 -8
- package/src/uint8Array.ts +2 -3
- package/src/unionParser.test.ts +22 -23
- package/src/unionParser.ts +6 -8
- package/src/unparser.test.ts +18 -34
- package/src/unparser.ts +13 -9
- package/src/unparserContext.ts +9 -13
- package/src/unparserError.ts +2 -1
- package/src/unparserImplementationInvariant.ts +1 -1
- package/src/unparserOutputCompanion.ts +1 -1
- package/src/zip.ts +2 -6
- package/src/zipParser.ts +10 -18
- package/src/zipUnparser.test.ts +1 -1
- package/src/zipUnparser.ts +52 -64
- package/tsconfig.json +7 -1
- package/xo.config.ts +15 -0
- package/.yarn/releases/yarn-4.5.3.cjs +0 -934
|
@@ -2,7 +2,7 @@ import test from 'ava';
|
|
|
2
2
|
import * as fc from 'fast-check';
|
|
3
3
|
import { testProp } from '@fast-check/ava';
|
|
4
4
|
import { createTerminatedArrayParser, createTerminatedArrayParserNaive, createTerminatedArrayParserUnsafe } from './terminatedArrayParser.js';
|
|
5
|
-
import { Parser, runParser } from './parser.js';
|
|
5
|
+
import { type Parser, runParser } from './parser.js';
|
|
6
6
|
import { stringParserInputCompanion, uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
7
7
|
import { HighResolutionTotalTimer } from './highResolutionTimer.js';
|
|
8
8
|
import { createElementParser } from './elementParser.js';
|
|
@@ -64,7 +64,7 @@ testProp(
|
|
|
64
64
|
|
|
65
65
|
if (
|
|
66
66
|
result.status === 'rejected'
|
|
67
|
-
|
|
67
|
+
&& naiveResult.status === 'rejected'
|
|
68
68
|
) {
|
|
69
69
|
result.reason.message = 'REDACTED';
|
|
70
70
|
naiveResult.reason.message = 'REDACTED';
|
|
@@ -96,10 +96,10 @@ testProp.serial(
|
|
|
96
96
|
})
|
|
97
97
|
.map(string => ({
|
|
98
98
|
string,
|
|
99
|
-
terminator: string.slice(0 - terminatorLength)
|
|
99
|
+
terminator: string.slice(0 - terminatorLength),
|
|
100
100
|
}))
|
|
101
101
|
.filter(({ string, terminator }) => string.split(terminator).length === 2)
|
|
102
|
-
))
|
|
102
|
+
)),
|
|
103
103
|
],
|
|
104
104
|
async (t, { string, terminator }) => {
|
|
105
105
|
const terminatedArrayParserNaive = createTerminatedArrayParserNaive(
|
|
@@ -138,7 +138,7 @@ testProp.serial(
|
|
|
138
138
|
};
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
const actualNaive = await naiveTotalTimer.measureAsync(() => runParser(
|
|
141
|
+
const actualNaive = await naiveTotalTimer.measureAsync(async () => runParser(
|
|
142
142
|
createTestWrapperParser(terminatedArrayParserNaive),
|
|
143
143
|
string,
|
|
144
144
|
stringParserInputCompanion,
|
|
@@ -146,7 +146,7 @@ testProp.serial(
|
|
|
146
146
|
|
|
147
147
|
t.is(actualNaive.string.length + actualNaive.terminator.length, string.length);
|
|
148
148
|
|
|
149
|
-
const actual = await optimizedTotalTimer.measureAsync(() => runParser(
|
|
149
|
+
const actual = await optimizedTotalTimer.measureAsync(async () => runParser(
|
|
150
150
|
createTestWrapperParser(terminatedArrayParser),
|
|
151
151
|
string,
|
|
152
152
|
stringParserInputCompanion,
|
|
@@ -164,7 +164,7 @@ test.serial(
|
|
|
164
164
|
t => {
|
|
165
165
|
t.true(
|
|
166
166
|
optimizedTotalTimer.time * 1n < naiveTotalTimer.time,
|
|
167
|
-
`Naive: ${naiveTotalTimer.time /
|
|
167
|
+
`Naive: ${naiveTotalTimer.time / 1_000_000n}ms, Optimized: ${optimizedTotalTimer.time / 1_000_000n}ms`,
|
|
168
168
|
);
|
|
169
169
|
},
|
|
170
170
|
);
|
|
@@ -184,10 +184,10 @@ testProp.serial(
|
|
|
184
184
|
})
|
|
185
185
|
.map(string => ({
|
|
186
186
|
string,
|
|
187
|
-
terminator: string.slice(0 - terminatorLength)
|
|
187
|
+
terminator: string.slice(0 - terminatorLength),
|
|
188
188
|
}))
|
|
189
189
|
.filter(({ string, terminator }) => string.split(terminator).length === 2)
|
|
190
|
-
))
|
|
190
|
+
)),
|
|
191
191
|
],
|
|
192
192
|
async (t, { string, terminator }) => {
|
|
193
193
|
const terminatedArrayParserNaive = createTerminatedArrayParserNaive(
|
|
@@ -234,7 +234,7 @@ testProp.serial(
|
|
|
234
234
|
|
|
235
235
|
t.is(actualNaive.string.length + actualNaive.terminator.length, string.length);
|
|
236
236
|
|
|
237
|
-
const actual = await unsafeTotalTimer.measureAsync(() => runParser(
|
|
237
|
+
const actual = await unsafeTotalTimer.measureAsync(async () => runParser(
|
|
238
238
|
createTestWrapperParser(terminatedArrayParserUnsafe),
|
|
239
239
|
string,
|
|
240
240
|
stringParserInputCompanion,
|
|
@@ -252,7 +252,7 @@ test.serial(
|
|
|
252
252
|
t => {
|
|
253
253
|
t.true(
|
|
254
254
|
unsafeTotalTimer.time * 1n < naiveTotalTimer.time,
|
|
255
|
-
`Naive: ${naiveTotalTimer.time /
|
|
255
|
+
`Naive: ${naiveTotalTimer.time / 1_000_000n}ms, Unsafe: ${unsafeTotalTimer.time / 1_000_000n}ms`,
|
|
256
256
|
);
|
|
257
257
|
},
|
|
258
258
|
);
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { getParserName, type Parser, setParserName } from './parser.js';
|
|
2
|
-
import { ParserParsingFailedError } from './parserError.js';
|
|
2
|
+
import { isParserParsingFailedError, ParserParsingFailedError } from './parserError.js';
|
|
3
3
|
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
4
4
|
import { promiseCompose } from './promiseCompose.js';
|
|
5
5
|
import { createUnionParser } from './unionParser.js';
|
|
6
6
|
|
|
7
7
|
class Terminated<T> {
|
|
8
|
-
constructor(
|
|
9
|
-
public readonly value: T,
|
|
10
|
-
) {}
|
|
8
|
+
constructor(public readonly value: T) {}
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export const createTerminatedArrayParserNaive = <ElementOutput, TerminatorOutput, Sequence>(
|
|
@@ -78,7 +76,7 @@ export const createTerminatedArrayParser = <ElementOutput, TerminatorOutput, Seq
|
|
|
78
76
|
getParserName(terminatorParser, 'anonymousTerminator'),
|
|
79
77
|
);
|
|
80
78
|
} catch (error) {
|
|
81
|
-
if (!(error
|
|
79
|
+
if (!(isParserParsingFailedError(error))) {
|
|
82
80
|
throw error;
|
|
83
81
|
}
|
|
84
82
|
} finally {
|
|
@@ -89,7 +87,7 @@ export const createTerminatedArrayParser = <ElementOutput, TerminatorOutput, Seq
|
|
|
89
87
|
|
|
90
88
|
return [ elements, terminatorValue ];
|
|
91
89
|
} catch (error) {
|
|
92
|
-
if (!(error
|
|
90
|
+
if (!(isParserParsingFailedError(error))) {
|
|
93
91
|
throw error;
|
|
94
92
|
}
|
|
95
93
|
} finally {
|
|
@@ -126,7 +124,7 @@ export const createTerminatedArrayParserUnsafe = <ElementOutput, TerminatorOutpu
|
|
|
126
124
|
|
|
127
125
|
return [ elements, terminatorValue ];
|
|
128
126
|
} catch (error) {
|
|
129
|
-
if (!(error
|
|
127
|
+
if (!(isParserParsingFailedError(error))) {
|
|
130
128
|
throw error;
|
|
131
129
|
}
|
|
132
130
|
} finally {
|
package/src/toAsyncIterator.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import invariant from
|
|
1
|
+
import invariant from 'invariant';
|
|
2
2
|
|
|
3
|
-
function isAsyncIterable<T>(value:
|
|
4
|
-
return value && typeof value[Symbol.asyncIterator] === 'function';
|
|
3
|
+
function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T> {
|
|
4
|
+
return typeof value === 'object' && value !== null && Symbol.asyncIterator in value && typeof (value as Record<symbol, unknown>)[Symbol.asyncIterator] === 'function';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function isIterable<T>(value:
|
|
8
|
-
return value && typeof value[Symbol.iterator] === 'function';
|
|
7
|
+
function isIterable<T>(value: unknown): value is Iterable<T> {
|
|
8
|
+
return typeof value === 'object' && value !== null && Symbol.iterator in value && typeof (value as Record<symbol, unknown>)[Symbol.iterator] === 'function';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function isIterator<T>(value:
|
|
12
|
-
return value && typeof value.next === 'function';
|
|
11
|
+
function isIterator<T>(value: unknown): value is Iterator<T> {
|
|
12
|
+
return typeof value === 'object' && value !== null && 'next' in value && typeof (value as Record<string, unknown>).next === 'function';
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function iteratorToAsyncIterator<T>(iterator: Iterator<T>): AsyncIterator<T> {
|
|
@@ -24,7 +24,7 @@ export function toAsyncIterator<T>(value: AsyncIterator<T> | AsyncIterable<T> |
|
|
|
24
24
|
|| value instanceof Uint8Array
|
|
25
25
|
) {
|
|
26
26
|
return (async function * () {
|
|
27
|
-
yield value as
|
|
27
|
+
yield value as T;
|
|
28
28
|
})();
|
|
29
29
|
}
|
|
30
30
|
|
package/src/uint8Array.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
export async function uint8ArrayAsyncIterableToUint8Array(
|
|
3
|
-
uint8ArrayAsyncIterable: AsyncIterable<Uint8Array> | Iterable<Uint8Array>,
|
|
4
|
-
): Promise<Uint8Array> {
|
|
2
|
+
export async function uint8ArrayAsyncIterableToUint8Array(uint8ArrayAsyncIterable: AsyncIterable<Uint8Array> | Iterable<Uint8Array>): Promise<Uint8Array> {
|
|
5
3
|
const chunks: Uint8Array[] = [];
|
|
6
4
|
for await (const chunk of uint8ArrayAsyncIterable) {
|
|
7
5
|
chunks.push(chunk);
|
|
8
6
|
}
|
|
7
|
+
|
|
9
8
|
return Buffer.concat(chunks);
|
|
10
9
|
}
|
package/src/unionParser.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { createUnionParser } from './unionParser.js';
|
|
3
|
-
import { Parser, runParser, setParserName } from './parser.js';
|
|
3
|
+
import { type Parser, runParser, setParserName } from './parser.js';
|
|
4
4
|
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
5
5
|
import { createArrayParser } from './arrayParser.js';
|
|
6
6
|
import { createExactElementParser } from './exactElementParser.js';
|
|
@@ -31,34 +31,32 @@ test('union of union of union', async t => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('sync and async child parsers', async t => {
|
|
34
|
-
const parser = createArrayParser(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
parserContext.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
34
|
+
const parser = createArrayParser(createUnionParser<string, string>([
|
|
35
|
+
async parserContext => {
|
|
36
|
+
parserContext.invariant(
|
|
37
|
+
parserContext.position % 2 === 0,
|
|
38
|
+
'Expected an even position.',
|
|
39
|
+
);
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
return parserContext.read(0);
|
|
42
|
+
},
|
|
43
|
+
parserContext => {
|
|
44
|
+
parserContext.invariant(
|
|
45
|
+
parserContext.position % 2 === 1,
|
|
46
|
+
'Expected an odd position.',
|
|
47
|
+
);
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
parserContext.skip(1);
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
51
|
+
return String.fromCodePoint('A'.codePointAt(0)! + parserContext.position - 1);
|
|
52
|
+
},
|
|
53
|
+
]));
|
|
56
54
|
|
|
57
55
|
const result = await runParser(parser, 'a?c?', stringParserInputCompanion, {
|
|
58
56
|
errorJoinMode: 'all',
|
|
59
57
|
});
|
|
60
58
|
|
|
61
|
-
t.deepEqual(result, 'aBcD'
|
|
59
|
+
t.deepEqual(result, [ ...'aBcD' ]);
|
|
62
60
|
});
|
|
63
61
|
|
|
64
62
|
test('multiple parsers succeeded error', async t => {
|
|
@@ -70,8 +68,9 @@ test('multiple parsers succeeded error', async t => {
|
|
|
70
68
|
const error = await t.throwsAsync(runParser(parser, 'foo', stringParserInputCompanion, {
|
|
71
69
|
errorJoinMode: 'all',
|
|
72
70
|
}), {
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
any: true,
|
|
72
|
+
name: 'ParserImplementationInvariantError',
|
|
73
|
+
}) as ParserError;
|
|
75
74
|
|
|
76
75
|
t.true(error.message.includes('foo'));
|
|
77
76
|
t.true(error.message.includes('foo1'));
|
package/src/unionParser.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { allSettledStream } from './allSettledStream.js';
|
|
2
2
|
import { getParserName, setParserName, type Parser } from './parser.js';
|
|
3
3
|
import { type ParserContext } from './parserContext.js';
|
|
4
|
-
import { ParserParsingFailedError } from './parserError.js';
|
|
4
|
+
import { isParserParsingFailedError, ParserParsingFailedError } from './parserError.js';
|
|
5
5
|
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
6
|
-
import { DeriveSequenceElement } from './sequence.js';
|
|
6
|
+
import { type DeriveSequenceElement } from './sequence.js';
|
|
7
7
|
|
|
8
8
|
const bigintReplacer = (_key: string, value: unknown) => {
|
|
9
9
|
if (typeof value === 'bigint') {
|
|
@@ -23,8 +23,8 @@ export const createUnionParser = <
|
|
|
23
23
|
parserImplementationInvariant(childParsers.length > 0, 'Union parser must have at least one child parser.');
|
|
24
24
|
|
|
25
25
|
type TaskContext = {
|
|
26
|
-
childParser: Parser<unknown, Sequence, Element
|
|
27
|
-
childParserContext: ParserContext<Sequence, Element
|
|
26
|
+
childParser: Parser<unknown, Sequence, Element>;
|
|
27
|
+
childParserContext: ParserContext<Sequence, Element>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const unionParser: Parser<Output, Sequence, Element> = async parserContext => {
|
|
@@ -60,9 +60,7 @@ export const createUnionParser = <
|
|
|
60
60
|
let didUnlookahead = false;
|
|
61
61
|
|
|
62
62
|
for await (const childParserResult of childParserResults) {
|
|
63
|
-
runningChildParserContexts = runningChildParserContexts.filter(
|
|
64
|
-
runningChildParserContext => runningChildParserContext !== childParserResult.context,
|
|
65
|
-
);
|
|
63
|
+
runningChildParserContexts = runningChildParserContexts.filter(runningChildParserContext => runningChildParserContext !== childParserResult.context);
|
|
66
64
|
|
|
67
65
|
if (childParserResult.status === 'fulfilled') {
|
|
68
66
|
successfulParserOutputs.push(childParserResult.value);
|
|
@@ -70,7 +68,7 @@ export const createUnionParser = <
|
|
|
70
68
|
} else {
|
|
71
69
|
const error = childParserResult.reason;
|
|
72
70
|
|
|
73
|
-
if (error
|
|
71
|
+
if (isParserParsingFailedError(error)) {
|
|
74
72
|
parserParsingFailedErrors.push(error);
|
|
75
73
|
} else {
|
|
76
74
|
throw error;
|
package/src/unparser.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import * as fc from 'fast-check';
|
|
3
|
-
import { runUnparser, Unparser } from './unparser.js';
|
|
4
|
-
import { stringUnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
5
3
|
import { testProp } from '@fast-check/ava';
|
|
4
|
+
import { runUnparser, type Unparser } from './unparser.js';
|
|
5
|
+
import { stringUnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
6
6
|
|
|
7
7
|
test('writeLater', async t => {
|
|
8
8
|
const stringToBeWrittenBefore = 'before writeLater\n';
|
|
@@ -16,7 +16,7 @@ test('writeLater', async t => {
|
|
|
16
16
|
let actualPositionBFromWithinWriteLater: number | undefined;
|
|
17
17
|
|
|
18
18
|
const unparser: Unparser<void, string> = async function * (_input, unparserContext) {
|
|
19
|
-
yield stringToBeWrittenBefore
|
|
19
|
+
yield stringToBeWrittenBefore;
|
|
20
20
|
|
|
21
21
|
expectedPositionA = unparserContext.position;
|
|
22
22
|
|
|
@@ -127,19 +127,13 @@ test('writeLater deep', async t => {
|
|
|
127
127
|
testProp(
|
|
128
128
|
'writeLater positions and lengths',
|
|
129
129
|
[
|
|
130
|
-
fc.array(
|
|
131
|
-
fc.oneof(
|
|
132
|
-
fc.array(
|
|
133
|
-
fc.oneof(
|
|
134
|
-
fc.array(
|
|
135
|
-
fc.string(),
|
|
136
|
-
),
|
|
137
|
-
fc.string(),
|
|
138
|
-
),
|
|
139
|
-
),
|
|
130
|
+
fc.array(fc.oneof(
|
|
131
|
+
fc.array(fc.oneof(
|
|
132
|
+
fc.array(fc.string()),
|
|
140
133
|
fc.string(),
|
|
141
|
-
),
|
|
142
|
-
|
|
134
|
+
)),
|
|
135
|
+
fc.string(),
|
|
136
|
+
)),
|
|
143
137
|
],
|
|
144
138
|
async (t, stringArray3) => {
|
|
145
139
|
const numberUnparser: Unparser<number, string> = async function * (input, unparserContext) {
|
|
@@ -148,12 +142,10 @@ testProp(
|
|
|
148
142
|
|
|
149
143
|
const createLengthPrefixedUnparser = <T>(
|
|
150
144
|
unparser: Unparser<T, string>,
|
|
151
|
-
): Unparser<T, string> => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
yield * unparserContext.writeEarlier(length, numberUnparser, unparserContext.position - length.positionEnd);
|
|
156
|
-
};
|
|
145
|
+
): Unparser<T, string> => async function * (input, unparserContext) {
|
|
146
|
+
const length = yield * unparserContext.writeLater(8);
|
|
147
|
+
yield * unparser(input, unparserContext);
|
|
148
|
+
yield * unparserContext.writeEarlier(length, numberUnparser, unparserContext.position - length.positionEnd);
|
|
157
149
|
};
|
|
158
150
|
|
|
159
151
|
const unparser0: Unparser<string, string> = createLengthPrefixedUnparser(async function * (input, unparserContext) {
|
|
@@ -166,23 +158,15 @@ testProp(
|
|
|
166
158
|
}
|
|
167
159
|
});
|
|
168
160
|
|
|
169
|
-
const unparser2: Unparser<
|
|
161
|
+
const unparser2: Unparser<Array<string | string[]>, string> = createLengthPrefixedUnparser(async function * (input, unparserContext) {
|
|
170
162
|
for (const stringArray2 of input) {
|
|
171
|
-
|
|
172
|
-
yield * unparser0(stringArray2, unparserContext);
|
|
173
|
-
} else {
|
|
174
|
-
yield * unparser1(stringArray2, unparserContext);
|
|
175
|
-
}
|
|
163
|
+
yield * (typeof stringArray2 === 'string' ? unparser0(stringArray2, unparserContext) : unparser1(stringArray2, unparserContext));
|
|
176
164
|
}
|
|
177
165
|
});
|
|
178
166
|
|
|
179
|
-
const unparser3: Unparser<
|
|
167
|
+
const unparser3: Unparser<Array<string | Array<string | string[]>>, string> = createLengthPrefixedUnparser(async function * (input, unparserContext) {
|
|
180
168
|
for (const stringArray3 of input) {
|
|
181
|
-
|
|
182
|
-
yield * unparser0(stringArray3, unparserContext);
|
|
183
|
-
} else {
|
|
184
|
-
yield * unparser2(stringArray3, unparserContext);
|
|
185
|
-
}
|
|
169
|
+
yield * (typeof stringArray3 === 'string' ? unparser0(stringArray3, unparserContext) : unparser2(stringArray3, unparserContext));
|
|
186
170
|
}
|
|
187
171
|
});
|
|
188
172
|
|
|
@@ -196,7 +180,7 @@ testProp(
|
|
|
196
180
|
|
|
197
181
|
const actualString = strings.join('');
|
|
198
182
|
|
|
199
|
-
type DeepArray<T> = T | DeepArray<T
|
|
183
|
+
type DeepArray<T> = T | Array<DeepArray<T>>;
|
|
200
184
|
|
|
201
185
|
function getExpectedString(stringArray: DeepArray<string>): string {
|
|
202
186
|
let expectedString = stringArray;
|
package/src/unparser.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import invariant from
|
|
2
|
-
import { DeriveSequenceElement } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import invariant from 'invariant';
|
|
2
|
+
import { type DeriveSequenceElement } from './sequence.js';
|
|
3
|
+
import {
|
|
4
|
+
type UnparserContext, UnparserContextImplementation, WriteEarlier, WriteLater,
|
|
5
|
+
} from './unparserContext.js';
|
|
6
|
+
import { type UnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
7
|
+
import { unparserImplementationInvariant } from './unparserImplementationInvariant.js';
|
|
6
8
|
|
|
7
9
|
type UnparserIterableValue<Sequence, Element> =
|
|
8
10
|
| Sequence
|
|
@@ -49,7 +51,7 @@ async function * elementsToSequences<
|
|
|
49
51
|
for await (const value of values) {
|
|
50
52
|
if (
|
|
51
53
|
value instanceof WriteLater
|
|
52
|
-
|
|
54
|
+
|| value instanceof WriteEarlier
|
|
53
55
|
) {
|
|
54
56
|
if (elements.length > 0) {
|
|
55
57
|
const sequence = unparserOutputCompanion.from(elements);
|
|
@@ -91,7 +93,9 @@ function wrapUnparserResult<Sequence, Element>(
|
|
|
91
93
|
unparserResult,
|
|
92
94
|
unparserOutputCompanion,
|
|
93
95
|
),
|
|
94
|
-
value =>
|
|
96
|
+
value => {
|
|
97
|
+
unparserContext.handleYield(value);
|
|
98
|
+
},
|
|
95
99
|
);
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -119,7 +123,7 @@ export async function * runUnparser<
|
|
|
119
123
|
type PushOutput = (value: Sequence | WriteLater<Sequence, Element>) => void;
|
|
120
124
|
type FinishOutput = () => void;
|
|
121
125
|
|
|
122
|
-
const iteratorStack: [ Iterator, PushOutput, FinishOutput ]
|
|
126
|
+
const iteratorStack: Array<[ Iterator, PushOutput, FinishOutput ]> = [
|
|
123
127
|
[
|
|
124
128
|
valuesWithoutElements[Symbol.asyncIterator](),
|
|
125
129
|
value => outputQueue.push(value),
|
|
@@ -130,7 +134,7 @@ export async function * runUnparser<
|
|
|
130
134
|
while (true) {
|
|
131
135
|
while (
|
|
132
136
|
outputQueue.length > 0
|
|
133
|
-
|
|
137
|
+
&& !(outputQueue[0] instanceof WriteLater)
|
|
134
138
|
) {
|
|
135
139
|
yield outputQueue.shift() as Sequence;
|
|
136
140
|
}
|
package/src/unparserContext.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/* eslint-disable prefer-arrow-callback */
|
|
2
1
|
|
|
3
|
-
import { Unparser, UnparserResult } from
|
|
4
|
-
import { UnparserOutputCompanion } from
|
|
5
|
-
import { unparserImplementationInvariant } from
|
|
6
|
-
import { parserImplementationInvariant } from
|
|
2
|
+
import { type Unparser, type UnparserResult } from './unparser.js';
|
|
3
|
+
import { type UnparserOutputCompanion } from './unparserOutputCompanion.js';
|
|
4
|
+
import { unparserImplementationInvariant } from './unparserImplementationInvariant.js';
|
|
5
|
+
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
7
6
|
|
|
8
7
|
export type UnparserContext<Sequence, Element> = {
|
|
9
8
|
get position(): number;
|
|
@@ -19,7 +18,7 @@ export type UnparserContext<Sequence, Element> = {
|
|
|
19
18
|
export class WriteLater<Sequence, Element> extends Error {
|
|
20
19
|
name = 'WriteLater';
|
|
21
20
|
|
|
22
|
-
constructor
|
|
21
|
+
constructor(
|
|
23
22
|
private readonly _position: number,
|
|
24
23
|
private readonly _length: number,
|
|
25
24
|
) {
|
|
@@ -105,13 +104,10 @@ export class UnparserContextImplementation<Sequence, Element> implements Unparse
|
|
|
105
104
|
);
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
handleYield(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
| WriteEarlier<Sequence, Element>
|
|
113
|
-
,
|
|
114
|
-
) {
|
|
107
|
+
handleYield(value:
|
|
108
|
+
| Sequence
|
|
109
|
+
| WriteLater<Sequence, Element>
|
|
110
|
+
| WriteEarlier<Sequence, Element>) {
|
|
115
111
|
if (value instanceof WriteEarlier) {
|
|
116
112
|
return;
|
|
117
113
|
}
|
package/src/unparserError.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnparserImplementationInvariantError } from './unparserError.js';
|
|
2
2
|
import { type Falsy, customInvariant, type ValueOrAccessor } from './customInvariant.js';
|
|
3
3
|
|
|
4
|
-
export function unparserImplementationInvariant<T>(value: T, format: ValueOrAccessor<string | string[]>, ...formatArguments:
|
|
4
|
+
export function unparserImplementationInvariant<T>(value: T, format: ValueOrAccessor<string | string[]>, ...formatArguments: unknown[]): Exclude<T, Falsy> {
|
|
5
5
|
return customInvariant(UnparserImplementationInvariantError, value, format, ...formatArguments);
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringParserInputCompanion, Uint8ArrayParserInputCompanion } from
|
|
1
|
+
import { StringParserInputCompanion, Uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
2
2
|
|
|
3
3
|
export type UnparserOutputCompanion<Sequence, Element> = {
|
|
4
4
|
is(value: unknown): value is Sequence;
|
package/src/zip.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
export type ZipCompression =
|
|
3
3
|
| 'store'
|
|
4
|
-
| 'deflate'
|
|
5
|
-
;
|
|
6
|
-
|
|
4
|
+
| 'deflate';
|
|
7
5
|
export type ZipEntryAttributes = {
|
|
8
6
|
};
|
|
9
7
|
|
|
@@ -27,9 +25,7 @@ export type ZipDirectoryEntry = ZipEntryCommon & {
|
|
|
27
25
|
|
|
28
26
|
export type ZipEntry =
|
|
29
27
|
| ZipFileEntry
|
|
30
|
-
| ZipDirectoryEntry
|
|
31
|
-
;
|
|
32
|
-
|
|
28
|
+
| ZipDirectoryEntry;
|
|
33
29
|
export type Zip = {
|
|
34
30
|
comment: string;
|
|
35
31
|
entries: ZipEntry[];
|
package/src/zipParser.ts
CHANGED
|
@@ -144,17 +144,13 @@ type ZipDataDescriptor = {
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
const zipDataDescriptorSignature: Uint8Array = Buffer.from('504b0708', 'hex');
|
|
147
|
-
const zipDataDescriptorSignatureParser = createExactSequenceParser<Uint8Array>(
|
|
148
|
-
zipDataDescriptorSignature
|
|
149
|
-
);
|
|
147
|
+
const zipDataDescriptorSignatureParser = createExactSequenceParser<Uint8Array>(zipDataDescriptorSignature);
|
|
150
148
|
|
|
151
149
|
const zipDataDescriptorParser: Parser<ZipDataDescriptor, Uint8Array> = promiseCompose(
|
|
152
150
|
createTupleParser([
|
|
153
|
-
createNegativeLookaheadParser(
|
|
154
|
-
zipLocalFileHeaderSignatureParser,
|
|
155
|
-
),
|
|
151
|
+
createNegativeLookaheadParser(zipLocalFileHeaderSignatureParser),
|
|
156
152
|
// FIXME: optional in spec
|
|
157
|
-
//createOptionalParser(zipDataDescriptorSignatureParser),
|
|
153
|
+
// createOptionalParser(zipDataDescriptorSignatureParser),
|
|
158
154
|
zipDataDescriptorSignatureParser,
|
|
159
155
|
uint32LEParser,
|
|
160
156
|
uint32LEParser,
|
|
@@ -186,12 +182,10 @@ export const zipLocalFileParser: Parser<ZipLocalFile, Uint8Array> = promiseCompo
|
|
|
186
182
|
parserCreatorCompose(
|
|
187
183
|
() => zipLocalFileHeaderParser,
|
|
188
184
|
zipLocalFileHeader => {
|
|
189
|
-
const sizeInDataDescriptor = Boolean(
|
|
190
|
-
zipLocalFileHeader.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
&& zipLocalFileHeader.uncompressedSize === 0
|
|
194
|
-
);
|
|
185
|
+
const sizeInDataDescriptor = Boolean(zipLocalFileHeader.generalPurposeBitFlag & 0b0000_0000_0000_1000
|
|
186
|
+
&& zipLocalFileHeader.crc32 === 0
|
|
187
|
+
&& zipLocalFileHeader.compressedSize === 0
|
|
188
|
+
&& zipLocalFileHeader.uncompressedSize === 0);
|
|
195
189
|
|
|
196
190
|
return createTupleParser([
|
|
197
191
|
async () => zipLocalFileHeader,
|
|
@@ -210,9 +204,7 @@ export const zipLocalFileParser: Parser<ZipLocalFile, Uint8Array> = promiseCompo
|
|
|
210
204
|
sizeInDataDescriptor
|
|
211
205
|
? (<T>(parser: T): T => parser)
|
|
212
206
|
: createOptionalParser
|
|
213
|
-
)(
|
|
214
|
-
zipDataDescriptorParser
|
|
215
|
-
),
|
|
207
|
+
)(zipDataDescriptorParser),
|
|
216
208
|
]);
|
|
217
209
|
},
|
|
218
210
|
)(),
|
|
@@ -257,7 +249,7 @@ const zipVersionMadeByParser: Parser<ZipVersionMadeBy, Uint8Array> = promiseComp
|
|
|
257
249
|
|
|
258
250
|
type ZipExternalFileAttributes = {
|
|
259
251
|
directory: boolean;
|
|
260
|
-
}
|
|
252
|
+
};
|
|
261
253
|
|
|
262
254
|
const dosExternalFileAttributesParser: Parser<ZipExternalFileAttributes, Uint8Array> = promiseCompose(
|
|
263
255
|
uint32LEParser,
|
|
@@ -499,7 +491,7 @@ export async function zipEntriesFromZipSegments({
|
|
|
499
491
|
|
|
500
492
|
const isDirectory = (
|
|
501
493
|
centralDirectoryHeader.externalFileAttributes.directory
|
|
502
|
-
|
|
494
|
+
|| commonFields.path.endsWith('/')
|
|
503
495
|
);
|
|
504
496
|
|
|
505
497
|
if (isDirectory) {
|
package/src/zipUnparser.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import fsPromises from 'node:fs/promises';
|
|
1
2
|
import { fc, testProp } from '@fast-check/ava';
|
|
2
3
|
import { temporaryFile } from 'tempy';
|
|
3
4
|
import { execa } from 'execa';
|
|
4
|
-
import fsPromises from 'node:fs/promises';
|
|
5
5
|
import { runUnparser } from './unparser.js';
|
|
6
6
|
import { createZipUnparser } from './zipUnparser.js';
|
|
7
7
|
import { uint8ArrayUnparserOutputCompanion } from './unparserOutputCompanion.js';
|