1 Star 0 Fork 0

huanjie / nodeunrar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

nodeunrar

Build Status npm version MIT License TypeScript

nodeunrar is a npm module to extract rar archive in pure JavaScript. It's combined by a Javascript adoption layer and JavaScript unRar library compiled by Emscripten from the C++ unrar library from http://www.rarlab.com/rar_add.htm .

Installation

You can install the module via npm:

npm install @huanjiesm/nodeunrar

Features

  • Fully support for RAR archive, because it comes from the official source code.
  • Unicode support, for both comment and file path/name.
  • API for Extraction to both memory and file system.

Unsupported Features

  • Volume archives are not supported.
  • Synchronize File System IO functions are used in File Extraction for the limitation of the library.
  • Files must be extracted at once now, can not be extracted one by one for progress indicator (may be improved later).

API to create the extractor

  • createExtractorFromData(data: ArrayBuffer, password?: string) - Create the Memory Extractor

    Options:

    • data : ArrayBuffer object of the RAR archive file.
    • password : Optional string for extraction password
  • createExtractorFromFile(filepath: string, targetPath?: string, password?: string) - Get the File Extractor

    Options:

    • filepath : File path of the RAR archive file.
    • targetPath : Optional string target folder
    • password : Optional string for extraction password

API of the extractor

  • getFileList() : Get the file list of the archive. Return: [state, result]
    • If function call failed
      • the state will be {state: "FAIL", reason: <FailReason>, msg: <string>}
      • the result will be null.
    • When function call success
      • the state will be {state: "SUCCESS"}
      • the result will be like:
{
  arcHeader: {
    comment: "",
    flags: {
      authInfo: false,
      headerEncrypted: false,
      lock: false,
      recoveryRecord: false,
      solid: false,
      volume: false,
    },
  }, fileHeaders: [
    {
      crc: 0,
      flags: {
        directory: false,
        encrypted: false,
        solid: false,
      },
      method: "Storing", 
      name: "FileName",
      packSize: 0,
      time: "2017-04-03T10:41:42.000",
      unpSize: 0,
      unpVer: "2.9", 
    },
    // ...
  ]
}
  • extractAll(): Extract all the files.

    Return: [state, result]

    • If function call failed, the response will be structed like return value above.
    • When function call success
      • the result will be like:
{
  arcHeader: {...} // Same as the arcHeader above
  files: [
    {
      fileHeader: {...} // Same as the fileHeader above
      extract: [state, extractedContent]
  ]
}

The state above will be same as the state of the return above, and the extractedContent will be null if file extract failed or in File extraction mode.

If extracted successful, the extractedContent will be Uint8Array object.

  • extractFiles(files: string[], password?: string): Extract the specific files

    Option:

    • files: File path list to be extracted.
    • password: A different to main password may be set on these specific files.

    Return:

    Same to the return value of extractAll(), the result will be stored in the same order of the input array files. If the specific file is not found in the archive, the file item of the files array will be null.

Example

var fs = require("fs");
var unrar = require("node-unrar-js");

// Read the archive file into a typedArray
var buf = Uint8Array.from(fs.readFileSync("a.rar")).buffer;
var extractor = unrar.createExtractorFromData(buf);

var list = extractor.getFileList();
if (list[0].state === "SUCCESS") {
  list[1].arcHeader...
  list[1].fileHeaders[...]
}

var extracted = extractor.extractAll();
var extracted = extractor.extractFiles(["1.txt", "1.txt"], "password")();
if (list[0].state === "SUCCESS") {
  list[1].arcHeader...
  list[1].files[0].fileHeader: ..
  if (list[1].files[0].extract[0].state === "SUCCESS") {
    list[1].files[0].extract[1] // Uint8Array 
  }
}

TypeScript

This module is written in TypeScript, you can import it directly in TypeScript and get the benefit of static type checking and auto-complete of IDE.

Development and Contribution

If you want to compile the module by yourself, please follow the steps below:

  • Pull the docker image for Emscripten (Please install the docker at first)

docker pull apiaryio/emcc

  • Download the c++ source of unRar library:

npm run prepare

  • Build for debug:

npm run buildDebug

  • Build for release

npm run buildRelease

  • Run Test

npm run test

License

This module is licensed under MIT.

Changelog

0.8.0:

  • First release
Copyright (c) 2017 Jianrong Yu. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

fork from https://github.com/YuJianrong/node-unrar.js.git 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/huanjie/nodeunrar.git
git@gitee.com:huanjie/nodeunrar.git
huanjie
nodeunrar
nodeunrar
master

搜索帮助