Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from david50407/fix/untar-last-part
Browse files Browse the repository at this point in the history
Correct untar padding removal when last part has size = 512
  • Loading branch information
BlackAsLight authored Aug 2, 2024
2 parents 5f07d4e + 755fe36 commit 0c90bc8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@doctor/tar-stream",
"version": "1.0.1",
"version": "1.0.2",
"exports": {
".": "./mod.ts",
"./tar": "./tar.ts",
Expand Down
26 changes: 26 additions & 0 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,29 @@ Deno.test('expandTarArchiveCheckingBodiesByteStream', async function () {
}
}
})

Deno.test('UnTarStream() with size equals to multiple of 512', async () => {
const size = 512 * 3
const data = Uint8Array.from({ length: size }, () => Math.floor(Math.random() * 256))

const readable = ReadableStream.from<TarInput>([
{
pathname: 'name',
size,
iterable: [data.slice()],
},
])
.pipeThrough(new TarStream())
.pipeThrough(new UnTarStream())

for await (const item of readable) {
if (item.readable) {
assertEquals(
Uint8Array.from(
(await Array.fromAsync(item.readable)).map((x) => [...x]).flat()
),
data
)
}
}
})
2 changes: 1 addition & 1 deletion untar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class UnTarStream {
lock = true
const { done, value } = await async function () {
const x = await reader.read()
if (!x.done && i-- === 1) {
if (!x.done && i-- === 1 && size % 512) {
x.value = x.value.slice(0, size % 512) // Slice off suffix padding.
}
return x
Expand Down

0 comments on commit 0c90bc8

Please sign in to comment.