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
Prev Previous commit
Next Next commit
Add format check in Untar
  • Loading branch information
arcatdmz committed May 11, 2019
commit 50f44c96926bfa1dad0ba6b879054df6746f8834
8 changes: 7 additions & 1 deletion archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MultiReader } from "../io/readers.ts";
import { BufReader } from "../io/bufio.ts";

const recordSize = 512;
const ustar = "ustar\u000000";

/**
* Simple file reader
Expand Down Expand Up @@ -328,7 +329,7 @@ export class Tar {
mtime: pad(mtime, 11),
checksum: " ",
type: "0", // just a file
ustar: "ustar\u000000\u0000",
ustar,
owner: opts.owner || "",
group: opts.group || "",
filePath: opts.filePath,
Expand Down Expand Up @@ -414,6 +415,11 @@ export class Untar {
throw new Error("checksum error");
}

const magic = decoder.decode(header.ustar)
if (magic !== ustar) {
throw new Error(`unsupported archive format: ${magic}`);
}

// get meta data
const meta: UntarOptions = {
fileName: decoder.decode(trim(header.fileName))
Expand Down