UNPKG

fast-extract

Version:

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

24 lines (23 loc) 799 B
import { Transform } from 'extract-base-iterator'; import fs from 'graceful-fs'; let DestinationExists = class DestinationExists extends Transform { _transform(chunk, _encoding, callback) { if (this.ready) return callback(null, chunk); fs.readdir(this.dest, (dirErr, names)=>{ this.ready = true; const err = !dirErr && names.length ? new Error(`Cannot overwrite ${this.dest} without force option`) : null; err ? callback(err) : callback(null, chunk); }); } constructor(dest, options = {}){ options = options ? { ...options, objectMode: true } : { objectMode: true }; super(options); this.dest = dest; } }; export { DestinationExists as default };