From 94d101d590bac929428f4e3e133c11b4aa211777 Mon Sep 17 00:00:00 2001 From: remorses Date: Thu, 24 Jul 2025 23:21:12 +0200 Subject: [PATCH 1/2] fix --- packages/tar-parser/src/lib/tar.test.ts | 13 +++++++++++++ packages/tar-parser/src/lib/tar.ts | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/tar-parser/src/lib/tar.test.ts b/packages/tar-parser/src/lib/tar.test.ts index c8e7042251b..d68eec3de71 100644 --- a/packages/tar-parser/src/lib/tar.test.ts +++ b/packages/tar-parser/src/lib/tar.test.ts @@ -497,4 +497,17 @@ describe('tar-stream test cases', () => { ], ]); }); + it('parses large github repo', async () => { + const response = await fetch( + 'https://codeload.github.com/vercel/next.js/tar.gz/refs/heads/canary', + ); + if (!response.ok) { + throw new Error(`Failed to fetch tar.gz: ${response.status} ${response.statusText}`); + } + const entries: [TarHeader][] = []; + await parseTar(response.body!.pipeThrough(new DecompressionStream('gzip')), async (entry) => { + entries.push([entry.header]); + }); + assert.ok(entries.length > 1000); + }); }); diff --git a/packages/tar-parser/src/lib/tar.ts b/packages/tar-parser/src/lib/tar.ts index 6bfe1d00194..7634776f23c 100644 --- a/packages/tar-parser/src/lib/tar.ts +++ b/packages/tar-parser/src/lib/tar.ts @@ -315,7 +315,6 @@ export class TarParser { } this.#header = parseTarHeader(block, this.#options); - switch (this.#header.type) { case 'gnu-long-path': case 'gnu-long-link-path': @@ -399,6 +398,13 @@ export class TarParser { this.#bodyController!.enqueue(this.#buffer!); this.#missing -= this.#buffer!.length; this.#buffer = null; + + // Check if we've finished reading the entire body + if (this.#missing === 0) { + this.#bodyController!.close(); + this.#bodyController = null; + this.#missing = overflow(this.#header!.size); + } } else { this.#bodyController!.enqueue(this.#read(this.#missing)); this.#bodyController!.close(); From 24c3ba7aac3323582dffb93a65e8e803db2847f9 Mon Sep 17 00:00:00 2001 From: remorses Date: Wed, 27 Aug 2025 12:24:51 +0200 Subject: [PATCH 2/2] Apply prettier and eslint fixes --- packages/tar-parser/src/lib/tar.test.ts | 6 +++--- packages/tar-parser/src/lib/tar.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/tar-parser/src/lib/tar.test.ts b/packages/tar-parser/src/lib/tar.test.ts index 4ae4c42e2b5..4c669759756 100644 --- a/packages/tar-parser/src/lib/tar.test.ts +++ b/packages/tar-parser/src/lib/tar.test.ts @@ -497,15 +497,15 @@ describe('tar-stream test cases', () => { ], ]) }) - + it('parses large github repo', async () => { - const response = await fetch( + let response = await fetch( 'https://codeload.github.com/vercel/next.js/tar.gz/refs/heads/canary', ) if (!response.ok) { throw new Error(`Failed to fetch tar.gz: ${response.status} ${response.statusText}`) } - const entries: [TarHeader][] = [] + let entries: [TarHeader][] = [] await parseTar(response.body!.pipeThrough(new DecompressionStream('gzip')), async (entry) => { entries.push([entry.header]) }) diff --git a/packages/tar-parser/src/lib/tar.ts b/packages/tar-parser/src/lib/tar.ts index de128522d11..f13bc88fed6 100644 --- a/packages/tar-parser/src/lib/tar.ts +++ b/packages/tar-parser/src/lib/tar.ts @@ -398,7 +398,7 @@ export class TarParser { this.#bodyController!.enqueue(this.#buffer!) this.#missing -= this.#buffer!.length this.#buffer = null - + // Check if we've finished reading the entire body if (this.#missing === 0) { this.#bodyController!.close()