Skip to content

Commit

Permalink
Merge pull request #2 from polyseam/std-tar
Browse files Browse the repository at this point in the history
refactor: use `@std/tar`
  • Loading branch information
johnstonmatt authored Sep 16, 2024
2 parents 96afc31 + d362943 commit 1e83cc8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
7 changes: 3 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polyseam/inflate-response",
"version": "1.1.2",
"version": "1.1.3",
"exports": "./mod.ts",
"tasks": {
"dev": "deno run --watch main.ts",
Expand All @@ -11,10 +11,9 @@
".github"
],
"imports": {
"@std/archive": "jsr:@std/[email protected]",
"@std/assert": "jsr:@std/assert@^0.221.0",
"@std/fs": "jsr:@std/[email protected]",
"@std/io": "jsr:@std/io@0.214.0",
"@std/path": "jsr:@std/[email protected]"
"@std/path": "jsr:@std/path@0.214.0",
"@std/tar": "jsr:@std/tar@^0.1.1"
}
}
38 changes: 15 additions & 23 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions inflate_response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { resolve as resolvePath } from "@std/path";
import { Untar } from "@std/archive/untar";
import { UntarStream } from "@std/tar/untar-stream";
import { ensureFile } from "@std/fs/ensure_file";
import { ensureDir } from "@std/fs/ensure_dir";
import { copy } from "@std/io/copy";
import * as path from "@std/path";

const supportedCompressionFormats = ["deflate", "gzip", "deflate-raw"] as const;
Expand Down Expand Up @@ -48,21 +47,21 @@ export async function inflateResponse(
await decompressedStream.pipeTo(inflatedTarball.writable);

using inflatedTarFile = await Deno.open(tarballPath, { read: true });
const untar = new Untar(inflatedTarFile);
const entries = inflatedTarFile.readable.pipeThrough(new UntarStream());

for await (const entry of untar) {
if (entry.type === "directory") {
await ensureDir(entry.fileName);
for await (const entry of entries) {
if (entry.readable === undefined) {
await ensureDir(entry.path);
continue;
}
await ensureDir(inflateDestination);
await ensureFile(path.join(inflateDestination, entry.fileName));
await ensureFile(path.join(inflateDestination, entry.path));
using file = await Deno.open(
path.join(inflateDestination, entry.fileName),
path.join(inflateDestination, entry.path),
{ write: true },
);
// <entry> is a reader.
await copy(entry, file);
await entry.readable.pipeTo(file.writable);
}
} else { // single file
using inflatedFile = await Deno.open(resolvePath(inflateDestination), {
Expand Down

0 comments on commit 1e83cc8

Please sign in to comment.