UNPKG

fast-extract

Version:

Extract contents from various archive types (tar, tar.bz2, tar.gz, tar.xz, tgz, zip)

27 lines (26 loc) 646 B
import once from 'call-once-fn'; import oo from 'on-one'; import createWriteStream from './createWriteStream.js'; export default function extract(source, dest, options_, callback) { const options = { source, ...options_ }; const res = createWriteStream(dest, options); // path if (typeof source === 'string') { const end = once(callback); res.on('error', end); res.write(source, 'utf8'); res.end(end); return; } // stream const stream = source.pipe(res); oo(stream, [ 'error', 'end', 'close', 'finish' ], callback); }