Skip to content

Commit 8c24522

Browse files
committed
fix zip
1 parent 29611ea commit 8c24522

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/utils/zip-entries.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import * as fs from 'fs-extra';
12
import os from 'os';
23
import path from 'path';
3-
import * as fs from 'fs-extra';
44
import {
55
type Entry,
6-
type ZipFile as YauzlZipFile,
76
open as openZipFile,
7+
type ZipFile as YauzlZipFile,
88
} from 'yauzl';
99
import { t } from './i18n';
1010

@@ -56,24 +56,33 @@ export function readEntryPrefix(
5656
}
5757

5858
let settled = false;
59+
let expectedDestroyError: Error | undefined;
5960
const cleanup = () => {
6061
stream.off('data', onData);
6162
stream.off('end', onEnd);
6263
stream.off('error', onError);
6364
};
64-
const finish = () => {
65+
const finish = (destroyStream = false) => {
6566
if (settled) {
6667
return;
6768
}
6869
settled = true;
69-
cleanup();
70+
stream.off('data', onData);
71+
stream.off('end', onEnd);
72+
if (!destroyStream) {
73+
stream.off('error', onError);
74+
}
7075
resolve(Buffer.concat(buffers, length));
76+
77+
if (destroyStream) {
78+
expectedDestroyError = new Error('zip entry prefix read complete');
79+
stream.destroy(expectedDestroyError);
80+
}
7181
};
7282
const onData = (chunk: Buffer) => {
7383
const remaining = maxBytes - length;
7484
if (remaining <= 0) {
75-
finish();
76-
stream.destroy();
85+
finish(true);
7786
return;
7887
}
7988

@@ -82,12 +91,15 @@ export function readEntryPrefix(
8291
buffers.push(slice);
8392
length += slice.length;
8493
if (length >= maxBytes) {
85-
finish();
86-
stream.destroy();
94+
finish(true);
8795
}
8896
};
8997
const onEnd = () => finish();
9098
const onError = (error: Error) => {
99+
if (settled && error === expectedDestroyError) {
100+
cleanup();
101+
return;
102+
}
91103
if (settled) {
92104
return;
93105
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
/* Module Resolution Options */
4242
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43-
"baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
43+
"ignoreDeprecations": "6.0",
4444
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4545
// "rootDirs": [
4646
// "src",
@@ -52,7 +52,8 @@
5252
// "types": [], /* Type declaration files to be included in compilation. */
5353
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
5454
"paths": {
55-
"@/*": ["src/*"]
55+
"*": ["./src/*"],
56+
"@/*": ["./src/*"]
5657
},
5758
"resolveJsonModule": true,
5859
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,

0 commit comments

Comments
 (0)