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

@planitar/rnfs-untar

v1.4.0

Published

Extract files from TAR archives in React Native environments

Downloads

93

Readme

rnfs-untar CI Coverage Status

rnfs-untar is a utility for extracting files from TAR archives in React Native environments. This library provides both a low-level API for granular control and high-level API functions for common tasks such as listing all files, finding a specific file, and reading the entire TAR archive.

Installation

npm install @planitar/rnfs-untar

High-Level API Usage

listFiles(tarFilePath: string): Promise<string[]>

Lists all files in the TAR archive.

import { listFiles } from '@planitar/rnfs-untar';

listFiles('/path/to/tar/archive.tar').then(files => {
  console.log('Files:', files);
});

findFile(tarFilePath: string, fileName: string | RegExp): Promise<TarFile | null>

Finds a specific file in the TAR archive.

import { findFile } from '@planitar/rnfs-untar';

// Match by exact full path.
findFile('/path/to/tar/archive.tar', 'specific/file.txt').then(file => {
  if (file) {
    console.log('File found:', file.header.name);
    console.log('File content:', (await file.read()).toString('utf-8'));
  } else {
    console.log('File not found.');
  }
});

// Match by regexp.
findFile('/path/to/tar/archive.tar', /\bfile\.txt$/).then(file => {
  if (file) {
    console.log('File found:', file.header.name);
    console.log('File content:', (await file.read()).toString('utf-8'));
  } else {
    console.log('File not found.');
  }
});

readTar(tarFilePath: string, callback: (file: TarFile) => Promise<boolean | void>): Promise<void>

Reads the entire TAR archive and calls the provided callback function for each file in the archive.

import { readTar } from '@planitar/rnfs-untar';

readTar('/path/to/tar/archive.tar', async (file) => {
  console.log('File:', file.header.name);
  console.log('Content:', (await file.read()).toString('utf-8'));
});

Low-Level API Usage

The low-level API provides direct access to the TarExtractor class.

import { TarExtractor } from '@planitar/rnfs-untar';

const tarExtractor = new TarExtractor();

tarExtractor.read('/path/to/tar/archive.tar', async (file) => {
  console.log('File:', file.header.name);
  console.log('Content:', (await file.read()).toString('utf-8'));
});

API Reference

TarExtractor

Low-level API for reading TAR archives.

read(tarFilePath: string, callback: (file: TarFile) => Promise<boolean | void>): Promise<void>

Reads the TAR archive at the given file path and calls the provided callback function for each file in the archive.

TarFile

Represents a file in a TAR archive.

header: TarFileHeader

The header information for the file.

read(): Promise<Buffer>

Reads and returns the contents of the file as a Buffer.

TarFileHeader

Represents the header of a file in a TAR archive.

name: string

The name of the file.

size: number

The size of the file.

typeFlag: string

The type flag of the file.

ustarIndicator: string

The ustar indicator of the file.

prefix: string

The prefix of the file.

isPax(): boolean

Returns true if the header is a PAX header, false otherwise.