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
Merged

Conversation

arcatdmz
Copy link
Contributor

@arcatdmz arcatdmz commented May 10, 2019

Tar (ustar) archiver

As a starting point to address #376,

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
Copy link
Member

ry commented May 10, 2019

Nice!

@arcatdmz
Copy link
Contributor Author

@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
Copy link
Member

ry 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants