GithubHelp home page GithubHelp logo

papb / zip Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 2.0 896 KB

Zipping & unzipping, simplified.

License: MIT License

TypeScript 100.00%
zip unzip util archive archiver compress compression file folder filesystem

zip's Introduction

@papb/zip Build Status

Zipping & unzipping, simplified.

Highlights

  • Written in TypeScript
  • Cross-platform
  • Simple Promise-based API, for your simple zipping needs
  • No external binaries needed
  • Outputs to temporary folder if you do not specify an output path

Install

$ npm install @papb/zip

Usage

const { zip, zipDirContents, unzip } = require('@papb/zip');

(async () => {
	await zip('path/to/file.txt', 'file.zip');
	await zip('path/to/folder/foo123', 'foo.zip');
	await zipDirContents('path/to/folder/bar', 'bar.zip');
	await unzip('baz.zip', 'path/to/folder/baz');

	// If you don't specify an output path, a temp path is used:
	const zipped = await zip('path/to/folder/foo');
	console.log(zipped);
	//=> '/path/to/some/temp/folder/output.zip'
	const unzipped = await unzip('foo.zip');
	console.log(unzipped);
	//=> '/path/to/some/temp/folder' (which will contain a
	//   single folder called 'foo123' in this example)
})();

TypeScript usage

@papb/zip is written in TypeScript and comes with complete type declarations. This means that you will have great code completions right in your editor, and also means that you can use it perfectly with TypeScript:

import { zip, zipDirContents, unzip } from '@papb/zip';
// ...

API

zip(fileOrFolderPath, [destinationPath])

TypeScript signature: zip(fileOrFolderPath: string, destinationPath?: string): Promise<string>

Creates a zip archive of the given file or folder, saving it in destinationPath. If destinationPath is not given, the zip file will be saved as output.zip in a freshly-created temporary folder.

This async function returns the absolute path to the generated zip file.

zipDirContents(folderPath, [destinationPath])

TypeScript signature: zipDirContents(folderPath: string, destinationPath?: string): Promise<string>

Creates a zip archive of the contents of the given folder, saving it in destinationPath. If destinationPath is not given, the zip file will be saved as output.zip in a freshly-created temporary folder.

This async function returns the absolute path to the generated zip file.

unzip(zipFilePath, [destinationContainerPath])

TypeScript signature: unzip(zipFilePath: string, destinationContainerPath?: string): Promise<string>

Extracts the zip file in zipFilePath into the folder specified in destinationContainerPath. If destinationContainerPath is not given, a freshly-created temporary folder will be used as container.

This async function returns the absolute path to the destination container folder.

License

MIT © Pedro Augusto de Paula Barbosa

zip's People

Contributors

dependabot[bot] avatar papb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

meirionhughes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.