npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rar-stream

v3.2.0

Published

Rar-Stream is a module for managing rar archives as node streams

Downloads

23

Readme

rar-stream

TESTS

Library for "unpacking" and reading files inside rar archives as node Readable streams.

Note: Requires node version >= 18.0.0

Note: Decompression is not implemented at the moment

Getting Started

Below example shows how to unpack local rar files by piping the inner files to the file system.

import fs from "fs";
import path from "path";
import { RarFilesPackage, LocalFileMedia } from "rar-stream";
const CWD = process.cwd();

const localRarFiles = [
  path.resolve(CWD, "./file.r00"),
  path.resolve(CWD, "./file.r01"),
  path.resolve(CWD, "./file.r02"),
  path.resolve(CWD, "./file.rar"),
].map((p) => new LocalFileMedia(p));

const rarFilesPackage = new RarFilesPackage(localRarFiles);

async function writeInnerRarFilesToDisk() {
  const innerFiles = await rarFilesPackage.parse();
  for (const innerFile of innerFiles) {
    innerFile
      .createReadStream({ start: 0, end: innerFile.length - 1 })
      .pipe(fs.createWriteStream(innerFile.name));
  }
}

await writeInnerRarFilesToDisk();

See example/webtorrent.js for a more advanced example.

Installing

Install from npm repo with:

npm i rar-stream

API

RarFilesPackage Api

Methods:

| Method | Description | | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | constructor | Takes an array of local file paths as strings or instances that satifies the FileMedia interface mentioned below. | | parse | Parses all rar files and returns a Promise with InnerFiles. |

Events:

| Event | Description | | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | parsing-start | Emitted when the parsing is started, happens when you call parse. Event args are a bundle represntation of all the rar files passed to the constructor. | | file-parsed | Emitted each time a rar file is parsed. The event argument is the RarFile just parsed, i.e .rxx in the chain. | | parsing-complete | Emitted when the parsing is completed. The event argument is an array of all the parsed InnerFiles. |

Example

const rarFilesPackage = new RarFilesPackage(localRarFiles);
rarFilesPackage.on('parsing-start', rarFiles => console.log(rarFiles))
rarFilesPackage.on('file-parsed', rarFile => console.log(rarFile.name))
rarFilesPackage.on('parsing-end', innerFiles => console.log(innerFiles))
const innerFiles = await rarFilesPackage.parse();

InnerFile Api

Implements the FileMedia interface.

Methods:

| Method | Description | | ---------------------------------------------- | ----------------------------------------------------------------------- | | createReadStream({start: number, end: number}) | Returns a Readable stream. The start and end interval is inclusive. | | readToEnd | Returns a Promise with a Buffer containing all the content of the file. |

Properties:

| Property | Description | | -------- | --------------------------------------------- | | name | The name of the file | | length | Returns the total number of bytes of the file |

Example

const innerFiles = await rarStreamPackage.parse();
const innerFileStream = innerFiles[0].createReadStream({ start: 0, end: 30});

FileMedia Interface

This is loosely enforced interface that makes this module interoptable with other node modules such as torrent-stream or webtorrent.

Should have the following shape:

 // FileMedia
 {
  createReadStream(interval: Interval): Readable,
  name: string,
  length: number // Length or size of the file in bytes
 }

 // Interval
 // start and end should be inclusive.
 {
  start: number,
  end: number
 }

Development

Running the tests

Run tests with:

npm test

Contributing

Post a new issue if you'd like to contribute in any way.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details