fast-extract
Version:
Extract contents from various archive types (tar, tar.bz2, tar.gz, tar.xz, tgz, zip)
24 lines (23 loc) • 798 B
JavaScript
import fs from 'fs';
import { Transform } from 'stream';
let DestinationNotExists = class DestinationNotExists extends Transform {
_transform(chunk, encoding, callback) {
if (this.ready) return callback(null, chunk, encoding);
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, encoding);
});
}
constructor(dest, options){
options = options ? {
...options,
objectMode: true
} : {
objectMode: true
};
super(options);
this.dest = dest;
}
};
export { DestinationNotExists as default };