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 #1 from david50407/fix/untar-readable-boundry
Browse files Browse the repository at this point in the history
Fixup untar readable boundry
  • Loading branch information
BlackAsLight authored Jul 31, 2024
2 parents 85db11c + f89f576 commit 5f07d4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 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.0",
"version": "1.0.1",
"exports": {
".": "./mod.ts",
"./tar": "./tar.ts",
Expand Down
5 changes: 5 additions & 0 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ Deno.test('expandTarArchiveCheckingBodiesDefaultStream', async function () {
size: text.length,
iterable: [text.slice()],
},
{
pathname: './text2.txt',
size: text.length,
iterable: [text.slice()],
},
])
.pipeThrough(new TarStream())
.pipeThrough(new UnTarStream())
Expand Down
9 changes: 4 additions & 5 deletions untar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

/**
* The original tar archive header format.
* The original tar archive header format.
*/
export interface OldStyleFormat {
name: string
Expand Down Expand Up @@ -188,7 +188,7 @@ export class UnTarStream {
readable: new ReadableStream({
type: 'bytes',
async pull(controller) {
if (i >= 0) {
if (i > 0) {
lock = true
const { done, value } = await async function () {
const x = await reader.read()
Expand All @@ -200,15 +200,13 @@ export class UnTarStream {
if (done) {
header = undefined
lock = false
controller.close()
controller.byobRequest?.respond(0)
controller.error('Tarball ended unexpectedly.')
return
}
if (controller.byobRequest?.view) {
const buffer = new Uint8Array(
controller.byobRequest.view.buffer,
)

const size = buffer.length
if (size < value.length) {
buffer.set(value.slice(0, size))
Expand All @@ -228,6 +226,7 @@ export class UnTarStream {
reader.cancel(reason)
}
controller.close()
controller.byobRequest?.respond(0)
}
},
async cancel(r) {
Expand Down

0 comments on commit 5f07d4e

Please sign in to comment.