@szydlovski/tar-buffer
v0.1.0
Published
utilities for working with tar archives as buffers
Downloads
4
Readme
tar-buffer
Simple utilities for extracting tar archives into buffers, and creating archive buffers from a list of paths and buffers. Uses the tar
package under the hood. Temporary files are written to the OS's temp folder.
Usage
npm i @szydlovski/tar-buffer
import { createTarBuffer, extractTarToBuffers } from '@szydlovski/tar-buffers';
(async () => {
const files = [
['atextfile.txt', Buffer.from('hello world')],
['nested_directory/anothertextfile.txt', Buffer.from('hello again')]
];
const archiveBuffer = await createTarBuffer(files);
const archiveContents = await extractTarToBuffers(archiveBuffer);
for (const [path, content] of archiveContents) {
console.log(`${path} contains: ${content.toString()}`);
}
// prints
// atextfile.txt contains: hello world
// nested_directory\anothertextfile.txt contains: hello again
})();
API
createTarBuffer(files[, gzip = true])
Creates a tar archive containing the provided files.
Arguments:
- files -
array
- the files to include in the archive, in the format[pathInArchive, bufferData]
, i.e.['hello.txt', Buffer.from('hello world')]
- gzip -
boolean
- optional, defaults totrue
, indicates whether the archive should be gzipped
Returns:
buffer
- containing the raw data of the created archive
extractTarToBuffers(data)
Extracts files from the buffer of a tar archive.
Arguments:
- data - 'buffer' - the archive to be extracted
Returns:
array
- containing the extracted file paths and their buffers, in the format[pathInArchive, bufferData]
, i.e.['hello.txt', Buffer.from('hello world')]