Skip to main content


Deno standard library
Go to Latest
class Tar
import { Tar } from "";


A class to create a tar archive. Tar archives allow for storing multiple files in a single file (called an archive, or sometimes a tarball). These archives typically have the '.tar' extension.


The workflow is to create a Tar instance, append files to it, and then write the tar archive to the filesystem (or other output stream). See the worked example below for details.


Tar archives are not compressed by default. If you want to compress the archive, you may compress the tar archive after creation, but this capability is not provided here.

File format and limitations

The ustar file format is used for creating the archive file. While this format is compatible with most tar readers, the format has several limitations, including:

  • Files must be smaller than 8GiB
  • Filenames (including path) must be shorter than 256 characters
  • Filenames (including path) cannot contain non-ASCII characters
  • Sparse files are not supported


Example 1

import { Tar } from "";
import { Buffer } from "";
import { copy } from "";

const tar = new Tar();

// Now that we've created our tar, let's add some files to it:

const content = new TextEncoder().encode("Some arbitrary content");
await tar.append("deno.txt", {
  reader: new Buffer(content),
  contentSize: content.byteLength,

// This file is sourced from the filesystem (and renamed in the archive)
await tar.append("filename_in_archive.txt", {
  filePath: "./filename_on_filesystem.txt",

// Now let's write the tar (with it's two files) to the filesystem
// use tar.getReader() to read the contents.

const writer = await"./out.tar", { write: true, create: true });
await copy(tar.getReader(), writer);




append(filenameInArchive: string, source: TarOptions)

Append a file or reader of arbitrary content to this tar archive. Directories appended to the archive append only the directory itself to the archive, not its contents. To add a directory and its contents, recursively append the directory's contents. Directories and subdirectories will be created automatically in the archive as required.

Get a Reader instance for this tar archive.