Skip to main content
Module

std/archive/untar.ts>Untar

Deno standard library
Go to Latest
class Untar
import { Untar } from "https://deno.land/std@0.177.0/archive/untar.ts";

A class to extract a tar archive

Examples

Example 1

import { Untar } from "https://deno.land/std@0.177.0/archive/untar.ts";
import { ensureFile } from "https://deno.land/std@0.177.0/fs/ensure_file.ts";
import { ensureDir } from "https://deno.land/std@0.177.0/fs/ensure_dir.ts";
import { copy } from "https://deno.land/std@0.177.0/streams/copy.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

  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 copy(entry, file);
}
reader.close();

Constructors

new
Untar(reader: Reader)

Properties

block: Uint8Array
reader: Reader

Methods

extract(): Promise<TarEntry | null>
[Symbol.asyncIterator](): AsyncIterableIterator<TarEntry>