npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mircrotar

v0.1.1

Published

Tiny and fast Tar utils for any JavaScript runtime!

Downloads

4

Readme

📼 mircrotar

npm version npm downloads bundle Codecov

Tiny and fast Tar utils for any JavaScript runtime!

🌳 Tiny (less than 2KB minified + gzipped) and tree-shakable

✨ Written with modern TypeScript and ESM format

✅ Works in any JavaScript runtime Node.js (18+), Bun, Deno, Browsers, and Edge Workers

🌐 Web Standard Compatible

🗜️ Built-in compression and decompression support

Installation

Install package:

# npm
npm install mircrotar

# yarn
yarn add mircrotar

# pnpm
pnpm install mircrotar

# bun
bun install mircrotar

Import:

// ESM
import {
  createTar,
  createTarGzip,
  createTarGzipStream,
  parseTar,
  parseTarGzip,
} from "mircrotar";

// CommonJS
const { createTar } = require("mircrotar");

Creating a tar archive

Easily create a new tar archive using the createTar utility.

The first argument is an array of files to archive:

  • name field is required and you can use / to specify files within sub-directories.
  • data field is optional for directories and can be either a String, ArrayBuffer or Uint8Array.
  • attrs field is optional for file attributes.

The second argument is for archive options. You can use attrs to set default attributes for all files (can still be overridden per file).

Possible attributes are:

  • mtime: Last modification time. The default is Date.now()
  • uid: Owner user id. The default is 1000
  • gid: Owner group id. The default is 1000
  • user: Owner user name. The default is ""
  • group: Owner user group. The default is ""
  • mode: file mode (permissions). Default is 664 (-rw-rw-r--) for files and 775 (-rwxrwxr-x) for directories

Example:

import { createTar } from "mircrotar";

const data = createTar(
  [
    { name: "README.md", data: "# Hello World!" },
    { name: "test", attrs: { mode: "777", mtime: 0 } },
    { name: "src/index.js", data: "console.log('wow!')" },
  ],
  { attrs: { user: "js", group: "js" } },
);

// Data is a Uint8Array view you can send or write to a file

Compression

You can optionaly use createTarGzip or createTarGzipStream to create a compressed tar data stream (returned value is a Promise<Uint8Array> or RedableStream piped to CompressionStream)

import { createTarGzip, createTarGzipStream } from "mircrotar";

createTarGzip([]); // Promise<Uint8Array>

createTarGzipStream([]); // RedableStream

Parsing a tar archive

Easily parse a tar archive using parseTar utility.

Example:

import { parseTar } from "mircrotar";

// Read tar data from file or other sources into an ArrayBuffer or Uint8Array

const files = parseTar(data);

/**
[
  {
    "type": "file",
    "name": "hello.txt",
    "size": 12,
    "data": Uint8Array [ ... ],
    "text": "Hello World!",
    "attrs": {
      "gid": 1750,
      "group": "",
      "mode": "0000664",
      "mtime": 1702076997,
      "uid": 1750,
      "user": "root",
    },
  },
  ...
]
 */

Parsed files array has two additional properties: size file size and text, a lazy getter that decodes data view as a string.

Decompression

If input is compressed, you can use parseTarGzip utility instead to parse it (it used DecompressionStream internally and return a Promise<Uint8Array> value)

import { parseTarGzip } from "mircrotar";

parseTarGzip(data); // Promise<Uint8Array>

Development

  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Inspired by ankitrohatgi/tarballjs

Published under the MIT License.