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

tar-fs

v3.0.6

Published

filesystem bindings for tar-stream

Downloads

77,776,000

Readme

tar-fs

Filesystem bindings for tar-stream.

npm install tar-fs

Usage

tar-fs allows you to pack directories into tarballs and extract tarballs into directories.

It doesn't gunzip for you, so if you want to extract a .tar.gz with this you'll need to use something like gunzip-maybe in addition to this.

const tar = require('tar-fs')
const fs = require('fs')

// packing a directory
tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))

// extracting a directory
fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))

To ignore various files when packing or extracting add a ignore function to the options. ignore is also an alias for filter. Additionally you get header if you use ignore while extracting. That way you could also filter by metadata.

const pack = tar.pack('./my-directory', {
  ignore (name) {
    return path.extname(name) === '.bin' // ignore .bin files when packing
  }
})

const extract = tar.extract('./my-other-directory', {
  ignore (name) {
    return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
  }
})

const extractFilesDirs = tar.extract('./my-other-other-directory', {
  ignore (_, header) {
    // pass files & directories, ignore e.g. symlinks
    return header.type !== 'file' && header.type !== 'directory'
  }
})

You can also specify which entries to pack using the entries option

const pack = tar.pack('./my-directory', {
  entries: ['file1', 'subdir/file2'] // only the specific entries will be packed
})

If you want to modify the headers when packing/extracting add a map function to the options

const pack = tar.pack('./my-directory', {
  map (header) {
    header.name = 'prefixed/'+header.name
    return header
  }
})

const extract = tar.extract('./my-directory', {
  map (header) {
    header.name = 'another-prefix/'+header.name
    return header
  }
})

Similarly you can use mapStream incase you wanna modify the input/output file streams

const pack = tar.pack('./my-directory', {
  mapStream (fileStream, header) {
    // NOTE: the returned stream HAS to have the same length as the input stream.
    // If not make sure to update the size in the header passed in here.
    if (path.extname(header.name) === '.js') {
      return fileStream.pipe(someTransform)
    }
    return fileStream
  }
})

const extract = tar.extract('./my-directory', {
  mapStream (fileStream, header) {
    if (path.extname(header.name) === '.js') {
      return fileStream.pipe(someTransform)
    }
    return fileStream
  }
})

Set options.fmode and options.dmode to ensure that files/directories extracted have the corresponding modes

const extract = tar.extract('./my-directory', {
  dmode: parseInt(555, 8), // all dirs should be readable
  fmode: parseInt(444, 8) // all files should be readable
})

It can be useful to use dmode and fmode if you are packing/unpacking tarballs between *nix/windows to ensure that all files/directories unpacked are readable.

Alternatively you can set options.readable and/or options.writable to set the dmode and fmode to readable/writable.

var extract = tar.extract('./my-directory', {
  readable: true, // all dirs and files should be readable
  writable: true, // all dirs and files should be writable
})

Set options.strict to false if you want to ignore errors due to unsupported entry types (like device files)

To dereference symlinks (pack the contents of the symlink instead of the link itself) set options.dereference to true.

Copy a directory

Copying a directory with permissions and mtime intact is as simple as

tar.pack('source-directory').pipe(tar.extract('dest-directory'))

Interaction with tar-stream

Use finalize: false and the finish hook to leave the pack stream open for further entries (see tar-stream#pack), and use pack to pass an existing pack stream.

const mypack = tar.pack('./my-directory', {
  finalize: false,
  finish (sameAsMypack) {
    mypack.entry({name: 'generated-file.txt'}, "hello")
    tar.pack('./other-directory', {
      pack: sameAsMypack
    })
  }
})

License

MIT