fast-extract
Version:
Extract contents from various archive types (tar, tar.bz2, tar.gz, tar.xz, tgz, zip)
1 lines • 3.74 kB
Source Map (JSON)
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/fast-extract/src/createPipeline.mjs"],"sourcesContent":["import zlib from 'zlib';\nimport bz2 from 'unbzip2-stream';\nimport optionalRequire from './optionalRequire.cjs';\n\n// lzma-native module compatiblity starts at Node 6\nconst major = +process.versions.node.split('.')[0];\nconst lzmaNative = major >= 10 ? optionalRequire('lzma-native') : null;\n\nconst TRANSORMS = {\n bz2: bz2,\n tgz: zlib.createUnzip.bind(zlib),\n gz: zlib.createUnzip.bind(zlib),\n xz: lzmaNative && lzmaNative.createDecompressor ? lzmaNative.createDecompressor.bind(lzmaNative) : undefined,\n};\n\nimport create7ZPipeline from './streams/pipelines/7z.mjs';\nimport createFilePipeline from './streams/pipelines/file.mjs';\nimport createTarPipeline from './streams/pipelines/tar.mjs';\nimport createZipPipeline from './streams/pipelines/zip.mjs';\n\nconst WRITERS = {\n zip: createZipPipeline,\n tar: createTarPipeline,\n tgz: createTarPipeline,\n '7z': create7ZPipeline,\n};\n\nimport DestinationNotExists from './streams/transforms/DestinationNotExists.mjs';\nimport DestinationRemove from './streams/transforms/DestinationRemove.mjs';\n\nimport extname from './extname.mjs';\nimport statsBasename from './sourceStats/basename.mjs';\n\nexport default function createPipeline(dest, options) {\n const type = options.type === undefined ? extname(statsBasename(options.source, options) || '') : options.type;\n\n const parts = type.split('.');\n const streams = [options.force ? new DestinationRemove(dest) : new DestinationNotExists(dest)];\n for (let index = parts.length - 1; index >= 0; index--) {\n // append transform\n const transform = TRANSORMS[parts[index]];\n if (transform) streams.push(transform());\n\n // finish with a write stream\n const writer = WRITERS[parts[index]];\n if (writer) return writer(dest, streams, options);\n }\n\n // default is to write the result to a file\n return createFilePipeline(dest, streams, options);\n}\n"],"names":["zlib","bz2","optionalRequire","major","process","versions","node","split","lzmaNative","TRANSORMS","tgz","createUnzip","bind","gz","xz","createDecompressor","undefined","create7ZPipeline","createFilePipeline","createTarPipeline","createZipPipeline","WRITERS","zip","tar","DestinationNotExists","DestinationRemove","extname","statsBasename","createPipeline","dest","options","type","source","parts","streams","force","index","length","transform","push","writer"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,iBAAiB;AACjC,OAAOC,qBAAqB,wBAAwB;AAEpD,mDAAmD;AACnD,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,aAAaL,SAAS,KAAKD,gBAAgB,iBAAiB;AAElE,MAAMO,YAAY;IAChBR,KAAKA;IACLS,KAAKV,KAAKW,WAAW,CAACC,IAAI,CAACZ;IAC3Ba,IAAIb,KAAKW,WAAW,CAACC,IAAI,CAACZ;IAC1Bc,IAAIN,cAAcA,WAAWO,kBAAkB,GAAGP,WAAWO,kBAAkB,CAACH,IAAI,CAACJ,cAAcQ;AACrG;AAEA,OAAOC,sBAAsB,6BAA6B;AAC1D,OAAOC,wBAAwB,+BAA+B;AAC9D,OAAOC,uBAAuB,8BAA8B;AAC5D,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,UAAU;IACdC,KAAKF;IACLG,KAAKJ;IACLT,KAAKS;IACL,MAAMF;AACR;AAEA,OAAOO,0BAA0B,gDAAgD;AACjF,OAAOC,uBAAuB,6CAA6C;AAE3E,OAAOC,aAAa,gBAAgB;AACpC,OAAOC,mBAAmB,6BAA6B;AAEvD,eAAe,SAASC,eAAeC,IAAI,EAAEC,OAAO;IAClD,MAAMC,OAAOD,QAAQC,IAAI,KAAKf,YAAYU,QAAQC,cAAcG,QAAQE,MAAM,EAAEF,YAAY,MAAMA,QAAQC,IAAI;IAE9G,MAAME,QAAQF,KAAKxB,KAAK,CAAC;IACzB,MAAM2B,UAAU;QAACJ,QAAQK,KAAK,GAAG,IAAIV,kBAAkBI,QAAQ,IAAIL,qBAAqBK;KAAM;IAC9F,IA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