Skip to content

Commit 7ad3a90

Browse files
authored
Fix: Handle partial unzip (#773)
1 parent 1511507 commit 7ad3a90

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

core.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ export class FileTypeParser {
597597

598598
return {};
599599
}
600+
}).catch(error => {
601+
if (!(error instanceof strtok3.EndOfStreamError)) {
602+
throw error; // Re-throw non-EndOfStreamError
603+
}
600604
});
601605

602606
return fileType ?? {

fixture/fixture2.zip

1.05 MB
Binary file not shown.

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ const names = {
290290
dat: [
291291
'fixture-unicode-tests',
292292
],
293+
zip: [
294+
'fixture',
295+
'fixture2',
296+
],
293297
};
294298

295299
// Define an entry here only if the file type has potential
@@ -363,6 +367,11 @@ async function testFromBuffer(t, expectedExtension, path) {
363367
const chunk = fs.readFileSync(path);
364368
await checkBufferLike(t, expectedExtension, chunk);
365369
await checkBufferLike(t, expectedExtension, new Uint8Array(chunk));
370+
371+
if (path.includes('fixture2.zip')) {
372+
await checkBufferLike(t, expectedExtension, chunk.buffer.slice(0, Math.floor(chunk.byteLength / 2)));
373+
}
374+
366375
await checkBufferLike(t, expectedExtension, chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength));
367376
}
368377

0 commit comments

Comments
 (0)