Skip to main content
Home

latest

A tiny tar file manipulation library.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (1.0.0)

tinytar

A tiny tar file manipulation library for Deno,

Features

  • 🎯 Zero dependencies (except for gzip compression)
  • 🚀 Lightweight and fast
  • 💪 TypeScript ready
  • 🦕 Deno-first

Installation

import * as tinytar from "jsr:@openjs/tinytar@1.0.0"; // Replace with your JSR username

Usage

Create a tar file

import { createTar, createTarGzip } from "jsr:@openjs/tinytar@1.0.0";

// Create a simple tar file
const files = [
  {
    name: "hello.txt",
    data: "Hello, World!",
  },
  {
    name: "docs",
    // No data means it's a directory
  },
];

const tarData = createTar(files);
await Deno.writeFile("output.tar", tarData);

// Create a gzipped tar file
const gzipData = await createTarGzip(files);
await Deno.writeFile("output.tar.gz", gzipData);

Parse a tar file

import { parseTar, parseTarGzip } from "jsr:@openjs/tinytar@1.0.0";

// Parse a tar file
const tarData = await Deno.readFile("input.tar");
const files = parseTar(tarData);

// Parse a gzipped tar file
const gzipData = await Deno.readFile("input.tar.gz");
const gzipFiles = await parseTarGzip(gzipData);

// Access file contents
console.log(files[0].text);  // For text files
console.log(files[0].data);  // For binary files

File Attributes

const files = [
  {
    name: "script.sh",
    data: "#!/bin/sh\necho 'Hello!'",
    attrs: {
      mode: "755",  // Execute permission
      uid: 1000,
      gid: 1000,
      user: "deno",
      group: "deno",
      mtime: Date.now(),
    },
  },
];

Examples

Check out the examples directory for more detailed examples:

API

Types

interface TarFileItem {
  name: string;
  data?: string | Uint8Array;
  attrs?: {
    mode?: string;    // File mode (e.g., "644", "755")
    uid?: number;     // User ID
    gid?: number;     // Group ID
    mtime?: number;   // Modification time
    user?: string;    // Username
    group?: string;   // Group name
  };
}

Functions

  • createTar(files: TarFileItem[]): Uint8Array
  • createTarGzip(files: TarFileItem[]): Promise<Uint8Array>
  • parseTar(data: ArrayBuffer | Uint8Array): ParsedTarFileItem[]
  • parseTarGzip(data: ArrayBuffer | Uint8Array): Promise<ParsedTarFileItem[]>

License

MIT

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";
or

Import directly with a jsr specifier

import * as tinytar from "jsr:@openjs/tinytar";

Add Package

pnpm i jsr:@openjs/tinytar
or (using pnpm 10.8 or older)
pnpm dlx jsr add @openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";

Add Package

yarn add jsr:@openjs/tinytar
or (using Yarn 4.8 or older)
yarn dlx jsr add @openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";

Add Package

vlt install jsr:@openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";

Add Package

npx jsr add @openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";

Add Package

bunx jsr add @openjs/tinytar

Import symbol

import * as tinytar from "@openjs/tinytar";