# zip-unzip-promise

> ZIP圧縮展開

Latest version **2.1.2** (published 2023-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install zip-unzip-promise
pnpm add zip-unzip-promise
yarn add zip-unzip-promise
bun add zip-unzip-promise
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2023-03-03 |
| First published | 2017-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | honeo |
| Maintainers | honeo |
| Keywords | zip, unzip, promise |

## Links

- npm: https://www.npmjs.com/package/zip-unzip-promise
- Repository: https://github.com/honeo/zip-unzip-promise
- Homepage: https://github.com/honeo/zip-unzip-promise#readme
- Issues: https://github.com/honeo/zip-unzip-promise/issues
- npm.io page: https://npm.io/package/zip-unzip-promise

## Dependencies (9)

- [archiver](https://npm.io/package/archiver.md) ^3.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [unzipper](https://npm.io/package/unzipper.md) ^0.9.15
- [jschardet](https://npm.io/package/jschardet.md) ^2.1.0
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.4.24
- [@honeo/check](https://npm.io/package/@honeo/check.md) ^1.8.0
- [console-wrapper](https://npm.io/package/console-wrapper.md) ^1.1.0
- [encoding-japanese](https://npm.io/package/encoding-japanese.md) ^1.0.29
- [sanitize-filename](https://npm.io/package/sanitize-filename.md) ^1.6.1

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.1.2 (latest) — 2023-03-03
- 2.1.1 — 2019-05-29
- 2.1.0 — 2019-05-29
- 2.0.2 — 2019-04-04
- 2.0.1 — 2019-02-05
- 2.0.0 — 2019-02-05
- 1.1.0 — 2017-06-22
- 1.0.3 — 2017-04-17
- 1.0.2 — 2017-04-16
- 1.0.1 — 2017-04-12
- 1.0.0 — 2017-04-12

## README

# zip-unzip-promise
* [honeo/zip-unzip-promise](https://github.com/honeo/zip-unzip-promise)
* [zip-unzip-promise](https://www.npmjs.com/package/zip-unzip-promise)


## なにこれ
ZIP圧縮・展開など。


## 使い方
```bash
$ npm i zip-unzip-promise
```
```js
const {zip, unzip, list} = require('zip-unzip-promise');
```


## API
* 出力先について
	- ファイルが既にあればスキップする。
	- ディレクトリがなければ作成する。
	- [node-sanitize-filename](https://github.com/parshap/node-sanitize-filename)で正規化する。

### options
| key       | type     | default | description                                                            |
|:--------- |:-------- | ------- | ---------------------------------------------------------------------- |
| encode    | string   | "utf8"  | 書庫内のパスに使われている文字コード。"auto"で自動検出。 [文字コード名](https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings)       |
| filter    | function |         | 出力するコンテンツ毎にobjectを引数に実行され、falseが返ればskipする。 |
| overwrite | boolean  | false   | 上書きを許可するか。                                                   |


### .zip(input, outputFilePath [, options])
引数1パスのファイル・ディレクトリまたはそれらの配列を元に圧縮する。
作成した圧縮ファイルの絶対パスを引数に解決するpromiseを返す。
```js
// file => archive
const zipPath = await zip('hoge.txt', 'hoge.zip');

// dir => dir/archive
const zipPath = await zip('hoge', 'output/hoge.zip');

// dir & file => archive
const zipPath = await zip([
	'./hoge', './fuga.ext'
], './piyo.zip');



/*
	options
*/

// overwrite: all
const zipPath = await zip('foo.ext', 'bar.zip', {
	overwrite: true
});

// overwrite: if old
const zipPath = await zip('foo.ext', 'bar.zip', {
	overwrite: true,
	filter({path, type}){
		const stats = fs.statSync(path);
		return stats.birthtime.getFullYear() < new Date().getFullYear();
	}
});
```


### .unzip(inputFilePath, outputDirPath [, options])
引数1パスの圧縮ファイルを展開する。
展開先ディレクトリの絶対パスを引数に解決するpromiseを返す。
```js
// archive => contents
const dirPath = await unzip('./hoge.zip', './');

// archive => dir/contents
const dirPath = await unzip('./hoge.zip', './output');



/*
	options
*/

// overwrite
const dirPath = await unzip('foo.zip', 'bar', {
	overwrite: true
});

// output: *.txt file only
const dirPath = await unzip('foo.zip', 'bar', {
	filter({path, type}){
		return type==='File' && /\.txt$/.test(path);
	}
});

// for not UTF-8
const dirPath = await unzip('archive.zip', './', {
	encode: 'auto' // or "sjis", "ascii"...
});
```


### .list(inputFilePath, [, options])
引数1パスの圧縮ファイル内のコンテンツ一覧を配列で取得する。
取得した配列を引数に解決するpromiseを返す。
```js
// [...pathString]
const arr = await list('hoge.zip');

// options
const arr = await list('hoge.zip', {encode: 'sjis'});
```



## Breaking Changes

### v1 => v2
* .zip()
	- 引数2が必須化。
* .unzip()
	- 引数2が必須化。

---
_Source: https://npm.io/package/zip-unzip-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
