unrar-promise

3.1.0 • Public • Published

unrar-promise

なにこれ

かんたん.rar展開モジュール。

使い方

$ npm i unrar-promise
import {unrar, list} from 'unrar-promise';

await unrar('archive.rar', './output');

API

  • 出力先について
    • ファイルが既にあればスキップする。
    • ディレクトリがなければ作成する。

options

key type default description
filter function 出力するコンテンツ毎にobjectを引数に実行され、falseが返ればskipする。
overwrite boolean false 上書きを許可するか。
password string 書庫のパスワード。
sanitize boolean true ファイル名をnode-sanitize-filenameで正規化するか。

unrar(input, outputDir [, options])

引数1パスの.rar書庫を引数2のディレクトリへ展開する。 展開先ディレクトリのパスを引数に解決するpromiseを返す。

// .rar path => "output"
const dirPath = await unrar('hoge.rar', 'output');

// or Buffer<.rar>
const dirPath = await unrar(arraybuffer, 'output');

// options
const dirPath = await unrar('hoge.rar', 'output', {
	filter({path, type, size}){
		return type==='file' && /\.txt$/.test(path); //  *.txt file only
	},
	overwrite: true,
	password: '123456'
});

list(input [, options])

引数1パスの.rar書庫が持つコンテンツ一覧をpromise<[...object]>で取得する。

const arr = await list('foobar.rar');

// or Buffer<.rar>
const arr = await list(arraybuffer);

// example result
[{
	path: 'foo',
	size: 0,
	type: 'directory'
}, {
	path: 'foo/bar.txt',
	size: 8,
	type: 'file',
}]

// options
const arr = await list('foobar.rar', {
	password: 'qwerty'
});

Breaking Changes

v2 => v3

  • CJS => ESM.
  • unrar()
    • options.filterに渡されるobject.typeが全て小文字になった。
      • "File" => "file"
    • options.filterに渡されるobject.pathが末尾に"/"を含まなくなった。
      • "foo/" => "foo"
  • list()
    • 返り値を[...string]から[...object]に変更。
    • 返り値のpathが末尾に"/"を含まなくなった。
      • "foo/" => "foo"

v1 => v2

  • .extract(), extractAll()
    • 廃止して.unrar()に統合。
  • .list()
    • 引数2をstringからobjectに変更。

Readme

Keywords

Package Sidebar

Install

npm i unrar-promise

Weekly Downloads

125

Version

3.1.0

License

MIT

Unpacked Size

15.2 kB

Total Files

10

Last publish

Collaborators

  • honeo