This repository contains a WebAssembly build of the UnRAR source with a minimal C API for listing and extracting RAR archives in browser and worker environments.
unrar/— upstream UnRAR source with a CMake build for WASMunrar/wasm/unrar_wasm.cpp— thin C API wrapperbuild/unrar.jsandbuild/unrar.wasm— generated WASM artifacts
Prerequisites:
- Emscripten installed (
emcmakeon PATH) - CMake 3.16+
Build:
emcmake cmake -S unrar -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -jThe WASM module exports two C functions:
rar_list(archivePath, listPath)- Writes a newline-separated file list to
listPath - Returns number of files on success or a negative error code
- Writes a newline-separated file list to
rar_extract_all(archivePath, outDir)- Extracts all files into
outDir - Returns number of files on success or a negative error code
- Extracts all files into
importScripts('unrar.js');
const Module = await createUnrarModule({
locateFile: (p) => new URL(p, self.location.href).toString()
});
Module.FS.mkdir('/work');
Module.FS.writeFile('/work/archive.rar', new Uint8Array(buf));
const listRes = Module.ccall('rar_list', 'number', ['string', 'string'], [
'/work/archive.rar',
'/work/list.txt'
]);
Module.FS.mkdir('/out');
const extractRes = Module.ccall('rar_extract_all', 'number', ['string', 'string'], [
'/work/archive.rar',
'/out'
]);- Built with
ALLOW_MEMORY_GROWTH=1andMAXIMUM_MEMORY=2GB. - Output is suitable for web and worker use (no Node target).
Built from UnRAR source snapshot copied into this repo on 2026-04-07.
UnRAR source: https://www.rarlab.com/rar/unrarsrc-7.2.1.tar.gz
UnRAR is distributed under the UnRAR license. See the upstream license.txt
in the source tree for full terms.
*** End Patch去了