GithubHelp home page GithubHelp logo

spacedriveapp / archive-wasm Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 881 KB

LibArchive compiled to WASM with a idiomatic JS api

License: GNU General Public License v3.0

Dockerfile 4.60% C 57.73% Shell 2.60% JavaScript 33.78% TypeScript 1.28%

archive-wasm's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.