UNPKG

fast-extract

Version:

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

32 lines (31 loc) 844 B
import fs from 'fs'; import oo from 'on-one'; import { Transform } from '../../compat/stream.js'; let PathToData = class PathToData extends Transform { _transform(chunk, _encoding, callback) { const fullPath = typeof chunk === 'string' ? chunk : chunk.toString(); const stream = fs.createReadStream(fullPath); stream.on('data', (chunk)=>{ this.push(chunk); }); oo(stream, [ 'error', 'end', 'close', 'finish' ], (err)=>{ !err || this.push(null); callback(err); }); } constructor(options){ options = options ? { ...options, objectMode: true } : { objectMode: true }; super(options); } }; export { PathToData as default };