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.
npm install @planitar/rnfs-untar
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);
});
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.');
}
});
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'));
});
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'));
});
Low-level API for reading TAR archives.
Reads the TAR archive at the given file path and calls the provided callback function for each file in the archive.
Represents a file in a TAR archive.
The header information for the file.
Reads and returns the contents of the file as a Buffer.
Represents the header of a file in a TAR archive.
The name of the file.
The size of the file.
The type flag of the file.
The ustar indicator of the file.
The prefix of the file.
Returns true
if the header is a PAX header, false
otherwise.