README
tarball-unpacker
Tarball unpacker tool for Node.js
API
extractFromFile
extracts a tarball file into a target directory.
import unpacker from 'tarball-unpacker'
// Specify a file and target directory
unpacker
.extractFromFile('/path/to/file.tgz', '/tmp/destination')
.then((files) => {
console.log(files) // An array of unpacked paths to files
console.log('Done!')
})
Listen to each file extracted:
import unpacker from 'tarball-unpacker'
unpacker
.configure({
silent: true,
onExtract: (entry) => {
console.log(entry.path)
}
})
.extractFromFile('/path/to/file.tgz', '/tmp/destination')
.then(() => {
console.log('Done!')
})
.catch((err) => {
console.log('Something went wrong ', err)
})
extractFromURL
extracts a tarball from URL into a target directory.
import unpacker from 'tarball-unpacker'
// Specify a URL and target directory
unpacker
.extractFromURL('http://www.arkaitzgarro.com/tarball.tgz', '/tmp/destination')
.then((files) => {
console.log(files) // An array of unpacked paths to files
console.log('Done!')
})
.catch((err) => {
console.log('Something went wrong ', err)
})
- Create instances of
unpacker
if needed
import {Unpacker} from 'tarball-unpacker'
// Create a new instance of Unpacker
const unpacker = new Unpacker()
unpacker
.extractFromURL('http://www.arkaitzgarro.com/tarball.tgz', '/tmp/destination')
.then(() => {
console.log('Done!')
})
.catch((err) => {
console.log('Something went wrong ', err)
})
Options
Available options for configure
method:
silent
(boolean): don't output any log message. Default istrue
.
Command line
It's also possible to use unpacker
as a command line utility, you just need to
install it globally with npm install -g tarball-unpacker
. Here is the help command
output.
Usage: unpacker (<source path> | <url>) <destination folder>
Options:
--version Show version number [boolean]
--help Show help [boolean]
Examples:
unpacker /tmp/tarball.tgz /tmp/unpacked
unpacker http://www.arkaitzgarro.com/tarball.tgz /tmp/unpacked