Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/archive/mod.ts>Untar

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class Untar
import { Untar } from "https://deno.land/std@0.194.0/archive/mod.ts";

A class to extract a tar archive

Examples

Example 1

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