"use strict";const fs=require("fs"),utils=require("../utils"),ready=require("get-ready"),streamifier=require("streamifier"),FlushWritable=require("flushwritable"),GzipUncompressStream=require("../gzip").UncompressStream,TarUncompressStream=require("../tar").UncompressStream;class TgzUncompressStream extends FlushWritable{constructor(r){super(r=r||{});const e=utils.clone(r);e.source=void 0,this._gzipStream=new GzipUncompressStream(e).on("error",r=>this.emit("error",r));const s=new TarUncompressStream(e).on("finish",()=>this.ready(!0)).on("entry",this.emit.bind(this,"entry")).on("error",r=>this.emit("error",r));this._gzipStream.pipe(s);const t=utils.sourceType(r.source);if("file"===t){const e=fs.createReadStream(r.source,r.fs);return e.on("error",r=>this.emit("error",r)),void e.pipe(this)}if("buffer"===t){const e=streamifier.createReadStream(r.source,r.streamifier);return e.on("error",r=>this.emit("error",r)),void e.pipe(this)}"stream"===t&&(r.source.on("error",r=>this.emit("error",r)),r.source.pipe(this))}_write(r,e,s){this._gzipStream.write(r,e,s)}_flush(r){this._gzipStream.end(),this.ready(r)}}ready.mixin(TgzUncompressStream.prototype),module.exports=TgzUncompressStream;