Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[archive] add Tar and Untar classes #388

Merged
merged 17 commits into from May 14, 2019

Conversation

2 participants
@arcatdmz
Copy link
Contributor

commented May 10, 2019

Tar (ustar) archiver

As a starting point to address #376,

  • I ported a simple tar archiver from https://github.com/beatgammit/tar-js
  • rewrote it to use async functions and Deno.Reader
  • and newly implemented the Untar class that reads and deflates tar archives.

Usage

To create a tar archive, use Tar class:

// initialize
const tar = new Tar();

// put data on memory
const content = new TextEncoder().encode("hello tar world!");
await tar.append("output.txt", {
  reader: new Deno.Buffer(content),
  contentSize: content.byteLength
});

// put a file
await tar.append("dir/tar.ts", { filePath });

// write tar data to a buffer
const writer = new Deno.Buffer(),
  wrote = await Deno.copy(writer, tar.getReader());

To deflate extract files from a tar archive, use Untar class:

// read data from a tar archive (use tar instance created in the above code)
const untar = new Untar(tar.getReader());
const buf = new Deno.Buffer();
const result = await untar.extract(buf);
const untarText = new TextDecoder("utf-8").decode(buf.bytes());
result.fileName === "output.txt";
untarText === "hello tar world!";

[Update] It seems like the term "deflate" denotes a specific compression algorithm and we should use a more general term like "extract". Renamed as such in 94e109b.

@ry

This comment has been minimized.

Copy link
Contributor

commented May 10, 2019

Nice!

@arcatdmz

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2019

@ry Thanks! I've updated some features and this PR is good to go on my side.

As a side note, these classes focus on in-memory operations using Deno.Reader and Deno.Writer, not file operations. To me, it's sufficient, but would it be better to have helper functions for file operations? (e.g., writing files from the information retrieved by Untar.extract(buf)...)

@ry

This comment has been minimized.

Copy link
Contributor

commented May 14, 2019

@arcatdmz This looks like a great first pass at tar functionality.

As a side note, these classes focus on in-memory operations using Deno.Reader and Deno.Writer, not file operations.

I think that's better actually as it's low-level. I guess we'll hear complaints from people if they come to use it but can't easily hook into it.

Thanks and sorry it took so long to land!

@ry

ry approved these changes May 14, 2019

@ry ry merged commit 98257ef into denoland:master May 14, 2019

5 checks passed

denoland.deno_std Build #20190514.20 succeeded
Details
denoland.deno_std (Linux) Linux succeeded
Details
denoland.deno_std (Mac) Mac succeeded
Details
denoland.deno_std (Windows) Windows succeeded
Details
license/cla Contributor License Agreement is signed.
Details

@arcatdmz arcatdmz deleted the arcatdmz:feat-archive-tar branch May 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.