std/archive
William Perron 69f3d67cb2
chore: remove Promise<void> return type annotation (#819)
There's a couple of instances where `Promise<void>` is still there,
those are the exceptions, for example functions that explicitely return
a `Promise` object or functions that return the promise from another
function call without any `await` statement.

used this one-liner to automatically remove everything:

```bash
grep -rli 'promise<void>' | xargs sed -i 's/: Promise<void>//g
```
2021-04-05 07:49:05 -04:00
..
testdata fix(archive): untar (denoland/deno#6217) 2021-02-01 10:46:57 +00:00
README.md feat: add io/buffer and io/util module (#808) 2021-03-22 22:45:35 +01:00
tar_test.ts chore: remove Promise<void> return type annotation (#819) 2021-04-05 07:49:05 -04:00
tar.ts chore: remove Promise<void> return type annotation (#819) 2021-04-05 07:49:05 -04:00

Usage

Tar

import { Tar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";
import { Buffer } from "https://deno.land/std@$STD_VERSION/io/buffer.ts";

const tar = new Tar();
const content = new TextEncoder().encode("Deno.land");
await tar.append("deno.txt", {
  reader: new 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

import { Untar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";
import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/ensure_file.ts";
import { ensureDir } from "https://deno.land/std@$STD_VERSION/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();