diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-10 23:10:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 17:10:47 -0400 |
commit | fa6f10219e096e0c2765628ae3d5bc733e489adb (patch) | |
tree | 680a758535b64e2bd1815e6209069700b01f980f /std/archive/README.md | |
parent | 408edbb065cb0a7b375d83df5c7f61f62b4d47e6 (diff) |
fix(std/archive): untar (#6217)
- Fix `Untar` for tarballs with multiple files (Currently throwing `"checksum error"`)
- Fix parsing, now all `ustar` versions should be supported. Linux `tar -cvf deno.tar dir/` is not working on master.
- Added `asyncIterator`
- Added README.md
Diffstat (limited to 'std/archive/README.md')
-rw-r--r-- | std/archive/README.md | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/std/archive/README.md b/std/archive/README.md new file mode 100644 index 000000000..efa258ca4 --- /dev/null +++ b/std/archive/README.md @@ -0,0 +1,60 @@ +# Usage + +## Tar + +```ts +import { Tar } from "https://deno.land/std/archive/tar.ts"; + +const tar = new Tar(); +const content = new TextEncoder().encode("Deno.land"); +await tar.append("deno.txt", { + reader: new Deno.Buffer(content), + contentSize: content.byteLength, +}); + +// Or specifying a filePath +await tar.append("land.txt", { + filePath: "./land.txt", +}); + +// use tar.getReader() to read the contents + +const writer = await Deno.open("./out.tar", { write: true, create: true }); +await Deno.copy(tar.getReader(), writer); +writer.close(); +``` + +## Untar + +```ts +import { Untar } from "https://deno.land/std/archive/tar.ts"; +import { ensureFile } from "https://deno.land/std/fs/ensure_file.ts"; +import { ensureDir } from "https://deno.land/std/fs/ensure_dir.ts"; + +const reader = await Deno.open("./out.tar", { read: true }); +const untar = new Untar(reader); + +for await (const entry of untar) { + console.log(entry); // metadata + /* + fileName: "archive/deno.txt", + fileMode: 33204, + mtime: 1591657305, + uid: 0, + gid: 0, + size: 24400, + type: 'file' + */ + + if (entry.type === "directory") { + await ensureDir(entry.fileName); + continue; + } + + await ensureFile(entry.fileName); + const file = await Deno.open(entry.fileName, { write: true }); + // <entry> is a reader + await Deno.copy(entry, file); +} +reader.close(); +``` |