Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/tar-parser/src/lib/tar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,18 @@ describe('tar-stream test cases', () => {
],
])
})

it('parses large github repo', async () => {
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}`)
}
let entries: [TarHeader][] = []
await parseTar(response.body!.pipeThrough(new DecompressionStream('gzip')), async (entry) => {
entries.push([entry.header])
})
assert.ok(entries.length > 1000)
})
})
8 changes: 7 additions & 1 deletion packages/tar-parser/src/lib/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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()
Expand Down