Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/papb/zip
Zipping & unzipping, simplified.
https://github.com/papb/zip
archive archiver compress compression file filesystem folder unzip util zip
Last synced: about 1 month ago
JSON representation
Zipping & unzipping, simplified.
- Host: GitHub
- URL: https://github.com/papb/zip
- Owner: papb
- License: mit
- Created: 2020-02-24T00:17:01.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-14T02:56:03.000Z (over 4 years ago)
- Last Synced: 2024-10-12T02:51:19.235Z (2 months ago)
- Topics: archive, archiver, compress, compression, file, filesystem, folder, unzip, util, zip
- Language: TypeScript
- Homepage:
- Size: 875 KB
- Stars: 19
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- jimsghstars - papb/zip - Zipping & unzipping, simplified. (TypeScript)
README
# @papb/zip ![Build Status](https://github.com/papb/zip/workflows/CI/badge.svg)
> Zipping & unzipping, simplified.
## Highlights
* Written in TypeScript
* Cross-platform
* [Simple Promise-based API](https://github.com/papb/zip#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
```js
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:
```ts
import { zip, zipDirContents, unzip } from '@papb/zip';
// ...
```## API
### zip(fileOrFolderPath, \[destinationPath\])
> *TypeScript signature:* `zip(fileOrFolderPath: string, destinationPath?: string): Promise`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`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`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](https://github.com/papb)