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

simple-archiver

v1.0.1

Published

Simple archiver for zip and tar formats that can handle multiple entries of files, directories, buffers, streams and strings

Downloads

496

Readme

Simple Archiver

Build Status

Archive multiple files, directories, buffers, streams and strings; supports 'zip' and 'tar' formats; can output a Buffer (default), Stream or to a path.

Can extract archives from a path, Buffer or Stream to a specified path.

Install

npm install simple-archiver --save

Usage

Archive

var archive = require('simple-archiver').archive;

archive(path)
  .then(archiveBuffer => console.log('Done! We should do something with the buffer.'))
  .catch(console.log);

archive(['/path/file.txt', '/path/auto-detect-dir-or-file-type', '/and-so-on']); // .then(...).catch(...);

// You can include Buffers, Streams and Strings in the archive as well (giving them a name)
archive([
 { data: '/path/file', type: 'file',      name: 'new-file-name'  },
 { data: '/path/dir',  type: 'directory', name: 'new-dir-name'  },
 { data: buffer,       type: 'buffer',    name: 'file1' },
 { data: stream,       type: 'stream',    name: 'file2' },
 { data: 'string',     type: 'string',    name: 'file3' }
], {
     format: 'tar',
     output: '/path/archive.tar'
}); // we're making it a 'tar' archive and saving it to a path

For optimal performance, you would use objects specifying the type and name of each entry. While not optimal, the type can be determined automatically, but the name can only be determined for paths (files and directories).

Extract

var extract = require('simple-archiver').extract;

// archive can be a path (String), Buffer or Stream
let archive = '/myarchive.tar';
extract(archive, '/path', { format: 'tar' }) // the format is 'zip' by default, so you have to specify it for 'tar'
  .then(() => console.log('Extraction finished!'))
  .catch(console.log);

Details

archive (entries, options)

=> Promise

Resolves to an archive Buffer (default), Stream or path depending on the chosen output.

- entries

Array of Objects | Array of Strings | Object | String

Object properties:

  • data - The data you wish to archive: file/directory path (String), Buffer, Stream or String (to save as a file);
  • type - (optional) Entry type: 'file', 'directory', 'other'; The type can be automatically determined (but if you know it, use it); Buffer, Stream and String are handled automatically and are classified here as 'other'; you can use any name instead of 'other' since it's the default;
  • name - (optional) The name the entry will have in the archive; may be a path within the archive (e.g. '/path/name'); Optional for 'file' and 'directory' (basenames are used by default), recommended for 'other' (a counter will be used if missing, starts at 0);

- options

(Optional) Object

Object properties:

  • format - (optional) Archive format: 'zip' (default), 'tar';
  • output - (optional) Output type: 'buffer' (default), 'stream', '/path'; If you enter a path string, the archive will be saved there and the resolve value will be the path string;

extract (archive, destination, options)

=> Promise

Extraction has finished when the promise resolves

- archive

String | Buffer | Stream

The archive path (String), Buffer or Stream.

- destination

String

The path to save the archive contents to.

- options

(Optional) Object

Object properties:

  • format - (optional) Archive format: 'zip' (default), 'tar';

Note: Extract doesn't know the format of your archive, so if it's not 'zip', remember to set it.

Extras

archiver

Used by archive() and provided to you if you need access to advanced options.

unzip & tar

Used by extract() and provided as unzip and tar from the module.

Note: Since unzip has been unmaintained for a very long time, it has been forked a number of times; this package uses a fork of a fork in order to keep things up to date and maintain a degree of control over its dependencies.

Issues & Features

You're welcome to make any feature requests, but remember that this package relies on the above three

Thanks

A big thank you to the above package creators and collaborators for making this possible.