Skip to content

spacedriveapp/archive-wasm

Repository files navigation

Archive-Wasm

LibArchive compiled to WASM with an idiomatic JavaScript API for extracting files from the most popular archive formats

Inspired by libarchivejs

Introduction

Archive-Wasm provides a WebAssembly (WASM) version of LibArchive to be used in NodeJS and Browsers through an idiomatic JS API, that allows you to effortlessly extract data from most of the popular archive formats.

Installation

To use Archive-Wasm in your project, you can install it via npm:

npm install archive-wasm

Environment Support

  • NodeJS >= 18
  • Chromium & Cia. >= 109
  • Safari >= 15
  • Firefox >= 102

It is possible that this lib works fine with previous versions than the listed, however these will be the minimum versions that the lib will be tested against

Usage

Here's a simple example of extracting data from an archive using Archive-Wasm:

import { extract, getEntryType } from 'archive-wasm'

// Load your archive data as an ArrayBuffer or any compatible Buffer type.
const archiveData = new Uint8Array([
  /* Archive Data */
])

for (const entry of extract(archiveData)) {
  if (entry.type === 'FILE' && entry.path.endsWith('lyrics.txt')) {
    console.log(`Found lyrics file: ${entry.path}, size: ${entry.size}`)
    console.log(new TextDecoder().decode(entry.data))
  }
}

Supported Archives Types

Archive-Wasm supports the same archive formats as the full version of LibArchive, with the exception of the xar format and grzip and lrzip compressions:

  • Reads a variety of formats, including 7z, tar, pax, cpio, zip, lha, ar, cab, mtree, rar, and ISO images.
  • Automatically handles archives compressed with compress, bzip2, gzip, lz4, lzip, lzop, lzma/xz, zstd.

Encrypted formats

Only encrypted zip is supported in LibArchive, other encrypted formats will throw an error during either the decoding step or when trying to read the actual file data, depending on how they implement encryption.

API

Check the docs

Contributing

Feel free to send PRs and open issues.

TODO

  • Add browser tests
  • Add cpio, lha, ar, mtree tests
  • Handle extracting sparse entries

License

Except where otherwise noted, all files in this project are licensed under the GNU General Public License v3.0 or later - see the LICENSE file for details.

About

LibArchive compiled to WASM with a idiomatic JS api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published