node-unrar-js
Advanced tools
Comparing version 1.0.5 to 1.0.6
import { Extractor } from './js/Extractor'; | ||
export * from './index.esm'; | ||
export interface ExtractorFromFileOptions { | ||
wasmBinary?: ArrayBuffer; | ||
filepath: string; | ||
@@ -9,2 +10,2 @@ targetPath?: string; | ||
} | ||
export declare function createExtractorFromFile({ filepath, targetPath, password, filenameTransform, }: ExtractorFromFileOptions): Promise<Extractor>; | ||
export declare function createExtractorFromFile({ wasmBinary, filepath, targetPath, password, filenameTransform, }: ExtractorFromFileOptions): Promise<Extractor>; |
@@ -17,4 +17,4 @@ "use strict"; | ||
__exportStar(require("./index.esm"), exports); | ||
async function createExtractorFromFile({ filepath, targetPath = '', password = '', filenameTransform = (filename) => filename, }) { | ||
const unrar = await (0, unrar_singleton_1.getUnrar)(); | ||
async function createExtractorFromFile({ wasmBinary, filepath, targetPath = '', password = '', filenameTransform = (filename) => filename, }) { | ||
const unrar = await (0, unrar_singleton_1.getUnrar)(wasmBinary && { wasmBinary }); | ||
const extractor = new ExtractorFile_1.ExtractorFile(unrar, filepath, targetPath, password, filenameTransform); | ||
@@ -21,0 +21,0 @@ unrar.extractor = extractor; |
import { Extractor } from './js/Extractor'; | ||
export * from './index.esm'; | ||
export interface ExtractorFromFileOptions { | ||
wasmBinary?: ArrayBuffer; | ||
filepath: string; | ||
@@ -9,2 +10,2 @@ targetPath?: string; | ||
} | ||
export declare function createExtractorFromFile({ filepath, targetPath, password, filenameTransform, }: ExtractorFromFileOptions): Promise<Extractor>; | ||
export declare function createExtractorFromFile({ wasmBinary, filepath, targetPath, password, filenameTransform, }: ExtractorFromFileOptions): Promise<Extractor>; |
import { ExtractorFile } from './js/ExtractorFile'; | ||
import { getUnrar } from './js/unrar.singleton'; | ||
export * from './index.esm'; | ||
export async function createExtractorFromFile({ filepath, targetPath = '', password = '', filenameTransform = (filename) => filename, }) { | ||
const unrar = await getUnrar(); | ||
export async function createExtractorFromFile({ wasmBinary, filepath, targetPath = '', password = '', filenameTransform = (filename) => filename, }) { | ||
const unrar = await getUnrar(wasmBinary && { wasmBinary }); | ||
const extractor = new ExtractorFile(unrar, filepath, targetPath, password, filenameTransform); | ||
@@ -7,0 +7,0 @@ unrar.extractor = extractor; |
{ | ||
"name": "node-unrar-js", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Pure JavaScript RAR archive extractor by compile the official unrar lib by Emscripten.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/YuJianrong/node-unrar.js", |
@@ -38,3 +38,3 @@ # node-unrar-js | ||
- `password?: string` : _Optional_ password | ||
- `wasmBinary? ArrayBuffer;` : _Optional_ Use in browser, the wasm binary must be loaded in the code and send to this function to load the wasm code | ||
- `wasmBinary? ArrayBuffer;` : _Optional_ Use in browser/webpack, the wasm binary must be loaded in the code and send to this function to load the wasm code | ||
@@ -49,2 +49,3 @@ - `async function createExtractorFromFile(options: ExtractorFromFileOptions): Promise<Extractor>` - Get the File Extractor | ||
- `filenameTransform?: (filename: string) => string`: _Optional_ transform the file name before it's created on file system | ||
- `wasmBinary? ArrayBuffer;` : _Optional_ Use in nodejs/webpack, the wasm binary must be loaded in the code and send to this function to load the wasm code in webpack based nodejs project (please read [Used in Webpack-bundled NodeJS Project](#use-in-webpack-bundled-nodejs-project) for more details). | ||
@@ -181,6 +182,23 @@ _Node_: This function is not available in EM2015 Module since the EM2015 Module is used for webpack in Browser. | ||
## Demo in webpack | ||
## Demo in Webpack | ||
This package can also be used in browser by Webpack, please visit the [demo project](https://github.com/YuJianrong/node-unrar.js/tree/master/demo/web) to see how to use it in webpack. | ||
## Use in Webpack-bundled NodeJS Project | ||
In most cases the exported ESModule is used in browser by Webpack, but in case if the NodeJs project (or an Electron project) is bundled by Webpack, the `wasmBinary` data must be loaded manually just like the browser by Webpack, it can be loaded like this: | ||
```Typescript | ||
import fs from 'fs'; | ||
import { createExtractorFromFile } from 'node-unrar-js/esm'; | ||
const wasmBinary = fs.readFileSync(require.resolve('node-unrar-js/esm/js/unrar.wasm')); | ||
const extractor = await createExtractorFromFile({ wasmBinary, filepath: './WithComment.rar' }); | ||
// const list = extractor.getFileList(); | ||
``` | ||
Note: the package must be loaded from `'node-unrar-js/esm'` instead of `'node-unrar-js'` to enable the function `createExtractorFromFile` in ES Module. | ||
## TypeScript | ||
@@ -218,2 +236,6 @@ | ||
#### 1.0.6 (2022-03-16) | ||
- Add `createExtractorFromFile` support in Webpack | ||
#### 1.0.5 (2022-02-28) | ||
@@ -220,0 +242,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
621569
1836
267