{"_id":"@01js/compressing","_rev":"2-ae68a8c19c4ca6666f406a9fb821adf2","name":"@01js/compressing","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@01js/compressing","version":"1.0.0","description":"Everything you need for compressing and uncompressing","main":"index.js","scripts":{"ts-test":"tsc -p ./test/fixtures/types/tsconfig.json","test":"egg-bin test && npm run ts-test","cov":"egg-bin cov","lint":"eslint .","ci":"npm run lint && npm run ts-test && npm run cov"},"repository":{"type":"git","url":"git+https://github.com/node-modules/compressing.git"},"keywords":["compress","uncompress","util","tgz","gzip","tar","zip","stream"],"typings":"index.d.ts","author":{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/node-modules/compressing/issues"},"homepage":"https://github.com/node-modules/compressing#readme","dependencies":{"flushwritable":"^1.0.0","get-ready":"^1.0.0","iconv-lite":"^0.5.0","mkdirp":"^0.5.1","pump":"^3.0.0","streamifier":"^0.1.1","tar-stream":"^1.5.2","yauzl":"^2.7.0","yazl":"^2.4.2"},"devDependencies":{"@types/mocha":"^5.2.5","@types/node":"^10.12.9","dir-compare":"^1.3.0","egg-bin":"^1.9.1","egg-ci":"^1.8.0","eslint":"^3.10.2","eslint-config-egg":"^3.2.0","mm":"^2.0.0","mz-modules":"^2.1.0","power-assert":"^1.4.2","rimraf":"^2.6.2","typescript":"^3.1.6","uuid":"^3.0.1"},"engines":{"node":">= 4.0.0"},"ci":{"version":"4, 6, 8, 10, 12","license":{"year":"2017","fullname":"node-modules and other contributors"}},"gitHead":"321d9d577b97f6a96fbf6d9c6a46655349a790d5","_id":"@01js/compressing@1.0.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","dist":{"integrity":"sha512-WTcsUNLtslT+jRR4eqMvkQjkU/MY0T168kmBvqSCspMxYZCPKYckMnOEtL9mJZWpbqOoDd6V0iG0aSzsDxhSSQ==","shasum":"2c50e1492f8711030e5d803cf09bd8cbd73535af","tarball":"https://registry.npmjs.org/@01js/compressing/-/compressing-1.0.0.tgz","fileCount":24,"unpackedSize":51433,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfRLnVCRA9TVsSAnZWagAA7OMP/it8n7Jc/wzymZrlsdCS\nDudXRbvGUOMPP3z8qpY95NcpXf3ZK/qc+WX1/qEKtsqR+Vwyy5qEzCuTRvxd\n1xQyGO2MaOiHT/e+lRJTYqtJOBlUM8f6qO52G/r/vBPKjTwNk292JZFuKOrc\nClD8tJx3ZBfpi+wIj5r4ocOWpvbtmnreehL8Ee/eInGGsSBtR2YEfq/nQrgg\nYkZUO/kLS4itzFCreqxLM8z5HMEHzj1DEpt6ipM2S8YDTTu/BLgVCqnJXkxL\nj/YuDWcQkdMI36013ulCV9QsqiAA+j4+h7JcAASDnM+o+twmsdHBEPGe8CGH\nkNha5u1OIsuqtfL9a2bZpFjjE8xjN54mIYdxhE2nNTFpGaioHa8iYeEWYsIk\nwinJ67eTH/3oFjTIpfnjrNEKVA10sf7fhIuhNp/98M2hN9mTph0oGavcJh6q\n6Zr4DoZcOXXstLbpdF0S8a1RmFqnJ0/X1S5sRpfwUBDU+dSgdHNJXTCLGfqp\noaNL78+4X/FkP04J7xf0iNXFUx+l5tHDT5fdKLycThDOGQZ7ArRU6L5i0x9n\nhbK0PlXs+Cz4uquJo3lew8CkZFNLXKPuzCYmxBwNCU1VS8eMGuJp9fbjWvAS\nL9jk+6R2rrTT5XhgHPK73Gi5IRHRXW/0aGQpI7mEUF3eFKt03ZFX1wttkNcL\nwgBg\r\n=iULg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGF4Bkuynt/zJHczbW7mE/Vh+7aOuQ5s/hjOZl/Ns+BcAiBClGiDOenxaHZzvxFf78o5ufOW52fWaZJ6CIpajNq33A=="}]},"maintainers":[{"name":"binperson","email":"549346275@qq.com"}],"_npmUser":{"name":"binperson","email":"549346275@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/compressing_1.0.0_1598339540940_0.5295181421546233"},"_hasShrinkwrap":false},"1.0.1":{"name":"@01js/compressing","version":"1.0.1","description":"Everything you need for compressing and uncompressing","main":"index.js","scripts":{"ts-test":"tsc -p ./test/fixtures/types/tsconfig.json","test":"egg-bin test && npm run ts-test","cov":"egg-bin cov","lint":"eslint .","ci":"npm run lint && npm run ts-test && npm run cov"},"repository":{"type":"git","url":"git+https://github.com/01js/compressing.git"},"keywords":["compress","uncompress","util","tgz","gzip","tar","zip","stream"],"typings":"index.d.ts","author":{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/01js/compressing/issues"},"homepage":"https://github.com/01js/compressing#readme","dependencies":{"flushwritable":"^1.0.0","get-ready":"^1.0.0","iconv-lite":"^0.5.0","mkdirp":"^0.5.1","pump":"^3.0.0","streamifier":"^0.1.1","tar-stream":"^1.5.2","yauzl":"^2.7.0","yazl":"^2.4.2"},"devDependencies":{"@types/mocha":"^5.2.5","@types/node":"^10.12.9","dir-compare":"^1.3.0","egg-bin":"^1.9.1","egg-ci":"^1.8.0","eslint":"^3.10.2","eslint-config-egg":"^3.2.0","mm":"^2.0.0","mz-modules":"^2.1.0","power-assert":"^1.4.2","rimraf":"^2.6.2","typescript":"^3.1.6","uuid":"^3.0.1"},"engines":{"node":">= 4.0.0"},"ci":{"version":"4, 6, 8, 10, 12","license":{"year":"2017","fullname":"node-modules and other contributors"}},"gitHead":"68779a42edd5398908c5f3856f911a8b103890fd","_id":"@01js/compressing@1.0.1","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","dist":{"integrity":"sha512-UJK9A9OsDLmyW1IIZZJ0s+qXEkQOj1WDiaf9AvfZUTwIxwH9lqQC6VcF+Rbs6ehtRAOdYj+JL1UfW0yl0yDoPQ==","shasum":"d0f6053647a9e6c3ac8b8ddec1b7270c4a9a0655","tarball":"https://registry.npmjs.org/@01js/compressing/-/compressing-1.0.1.tgz","fileCount":24,"unpackedSize":51457,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfROK3CRA9TVsSAnZWagAA+5kQAI0AR26yRPND9BlaYuQH\noe1zjUEZcInDxbS7Tvzd4WeYWrnCyUw8QF4K3r/GJo1hUXbYoHk94RaWIx3a\nWoQCglsU71Hz9MCUrcBL04Wb3DOn0RdNS0PDjDOZZQPug3Erc0xDDcLYOJxt\nNPAFuDWa8r3Wp83tYy2cErk8s47eugfZv6vWBglWGiTNjCfwhLrQ6COmTvZL\nRj8ebcWOUOMXYIVlYdy9q/T1mapNWzCHbbtDvcbP8ShC1hsOYBnVFq9fGrBc\nRgOzr95Uh6q72I3j8QUm/4yICw7Bzt3GE0booE0V2Sb5iPCkrezLOnqJgT4A\nMCBHxG2rAPT88mU1PLfKKUJzkJh0nwM66Ze+o/7crbXXwzSOfNkMRldACH5T\n0KDu/AD9kvLYhgBKjOqIwdSR1EgVyu8ifX+WxW48h1SVJ+YtP+Sc//gY/dxT\nZRkbgsv05Hi6TtaUQe8oTwWq170RJgpoovBS7Xe+ZCPp/t2En3Eb3eOQH3DI\nGAfsf3fI7r/q0meN1t5uYpbYJ882/TLDEmdY4bEL+wwPX9fFH2MuBs+u2QxH\nlGVEK4JzWjcv9SMj0g0vuveZLFCrGaQusij7WvD2p6KtGfKFtjv12K3l9vhc\n/cXT/utGCC39ry1nxiX9wHumqxr0TCJOYz86cT6WPncB2tV3AzCHwNEsz3QX\n0tr8\r\n=B8aJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA4xmUo9oilGrTQO0+rvnzhMMR3mi2BQZPdpR/+hAfTKAiEAoOzAzvQ2biYJO32l4kuER5QeYm1DzRo8MC+KmFOAuNg="}]},"maintainers":[{"name":"binperson","email":"549346275@qq.com"}],"_npmUser":{"name":"binperson","email":"549346275@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/compressing_1.0.1_1598350006597_0.9010434529499345"},"_hasShrinkwrap":false}},"time":{"created":"2020-08-25T07:12:20.732Z","1.0.0":"2020-08-25T07:12:21.053Z","modified":"2022-04-04T10:25:53.557Z","1.0.1":"2020-08-25T10:06:46.744Z"},"maintainers":[{"name":"binperson","email":"549346275@qq.com"}],"description":"Everything you need for compressing and uncompressing","homepage":"https://github.com/01js/compressing#readme","keywords":["compress","uncompress","util","tgz","gzip","tar","zip","stream"],"repository":{"type":"git","url":"git+https://github.com/01js/compressing.git"},"author":{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com"},"bugs":{"url":"https://github.com/01js/compressing/issues"},"license":"MIT","readme":"# compressing\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/compressing.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/compressing\n[travis-image]: https://img.shields.io/travis/node-modules/compressing.svg?style=flat-square\n[travis-url]: https://travis-ci.org/node-modules/compressing\n[codecov-image]: https://codecov.io/gh/node-modules/compressing/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/compressing\n[david-image]: https://img.shields.io/david/node-modules/compressing.svg?style=flat-square\n[david-url]: https://david-dm.org/node-modules/compressing\n[snyk-image]: https://snyk.io/test/npm/compressing/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/compressing\n[download-image]: https://img.shields.io/npm/dm/compressing.svg?style=flat-square\n[download-url]: https://npmjs.org/package/compressing\n\nThe missing compressing and uncompressing lib for node.\n\nCurrently supported:\n\n- tar\n- gzip\n- tgz\n- zip\n\n## Install\n\n```bash\nnpm install @01js/compressing\n```\n\n## Usage\n\n### Compress a single file\n\nUse gzip as an example, tar, tgz and zip is same as gzip.\n\n__promise style__\n\n```js\nconst compressing = require('@01js/compressing');\n\n// compress a file\ncompressing.gzip.compressFile('file/path/to/compress', 'path/to/destination.gz')\n.then(compressDone)\n.catch(handleError);\n\n// compress a file buffer\ncompressing.gzip.compressFile(buffer, 'path/to/destination.gz')\n.then(compressDone)\n.catch(handleError);\n\n// compress a stream\ncompressing.gzip.compressFile(stream, 'path/to/destination.gz')\n.then(compressDone)\n.catch(handleError);\n```\n\n__stream style__\n\n```js\nconst compressing = require('@01js/compressing');\n\nnew compressing.gzip.FileStream({ source: 'file/path/to/compress' })\n  .on('error', handleError)\n  .pipe(fs.createWriteStream('path/to/destination.gz'))\n  .on('error', handleError);\n\n// It's a transform stream, so you can pipe to it\nfs.createReadStream('file/path/to/compress')\n  .on('error', handleError)\n  .pipe(new compressing.gzip.FileStream())\n  .on('error', handleError)\n  .pipe(fs.createWriteStream('path/to/destination.gz'))\n  .on('error', handleError);\n\n// You should take care of stream errors in caution, use pump to handle error in one place\nconst pump = require('pump';)\nconst sourceStream = fs.createReadStream('file/path/to/compress')\nconst gzipStream = new compressing.gzip.FileStream();\nconst destStream = fs.createWriteStream('path/to/destination.gz');\npump(sourceStream, gzipStream, destStream, handleError);\n```\n\n\n### Compress a dir\n\nUse tar as an example, tgz and zip is same as gzip.\n\n__Gzip only support compressing a single file. if you want to compress a dir with gzip, then you may need tgz instead.__\n\n__promise style__\n\n```js\nconst compressing = require('@01js/compressing');\ncompressing.tar.compressDir('dir/path/to/compress', 'path/to/destination.tar')\n.then(compressDone)\n.catch(handleError);\n```\n\n__stream style__\n\n```js\nconst compressing = require('@01js/compressing');\n\nconst tarStream = new compressing.tar.Stream();\ntarStream.addEntry('dir/path/to/compress');\n\ntarStream\n  .on('error', handleError)\n  .pipe(fs.createWriteStream('path/to/destination.tar'))\n  .on('error', handleError);\n\n// You should take care of stream errors in caution, use pump to handle error in one place\nconst tarStream = new compressing.tar.Stream();\ntarStream.addEntry('dir/path/to/compress');\nconst destStream = fs.createWriteStream('path/to/destination.tar');\npump(tarStream, destStream, handleError);\n```\n\nStream is very powerful, you can compress multiple entries in it;\n\n```js\nconst tarStream = new compressing.tar.Stream();\n// dir\ntarStream.addEntry('dir/path/to/compress');\n\n// file\ntarStream.addEntry('file/path/to/compress');\n\n// buffer\ntarStream.addEntry(buffer);\n\n// stream\ntarStream.addEntry(stream);\n\nconst destStream = fs.createWriteStream('path/to/destination.tar');\npipe(tarStream, destStream, handleError);\n```\n\n### Uncompress a file\n\n__promise style__\n\n```js\nconst compressing = require('@01js/compressing');\n\n// uncompress a file\ncompressing.tgz.uncompress('file/path/to/uncompress.tgz', 'path/to/destination/dir')\n.then(uncompressDone)\n.catch(handleError);\n\n// uncompress a file buffer\ncompressing.tgz.uncompress(buffer, 'path/to/destination/dir')\n.then(uncompressDone)\n.catch(handleError);\n\n// uncompress a stream\ncompressing.tgz.uncompress(stream, 'path/to/destination/dir')\n.then(uncompressDone)\n.catch(handleError);\n```\n\n**Note: tar, tgz and zip have the same uncompressing API as above: destination should be a path of a directory, while that of gzip is slightly different: destination must be a file or filestream.**\n\n\nAnd working with urllib is super easy. Let's download a tgz file and uncompress to a directory:\n\n```js\nconst urllib = require('urllib');\nconst targetDir = require('os').tmpdir();\nconst compressing = require('@01js/compressing');\n\nurllib.request('http://registry.npmjs.org/pedding/-/pedding-1.1.0.tgz', {\n  streaming: true,\n  followRedirect: true,\n})\n.then(result => compressing.tgz.uncompress(result.res, targetDir))\n.then(() => console.log('uncompress done'))\n.catch(console.error);\n```\n\n__stream style__\n\n```js\nconst compressing = require('@01js/compressing');\nconst mkdirp = require('mkdirp');\n\nfunction onEntry(header, stream, next) => {\n  stream.on('end', next);\n\n  // header.type => file | directory\n  // header.name => path name\n\n  if (header.type === 'file') {\n    stream.pipe(fs.createWriteStream(path.join(destDir, header.name)));\n  } else { // directory\n    mkdirp(path.join(destDir, header.name), err => {\n      if (err) return handleError(err);\n      stream.resume();\n    });\n  }\n}\n\nnew compressing.tgz.UncompressStream({ source: 'file/path/to/uncompress.tgz' })\n  .on('error', handleError)\n  .on('finish', handleFinish) // uncompressing is done\n  .on('entry', onEntry);\n\n// It's a writable stream, so you can pipe to it\nfs.createReadStream('file/path/to/uncompress')\n  .on('error', handleError)\n  .pipe(new compressing.tgz.UncompressStream())\n  .on('error', handleError)\n  .on('finish', handleFinish) // uncompressing is done\n  .on('entry', onEntry);\n```\n\n**Note: tar, tgz and zip have the same uncompressing streaming API as above: it's a writable stream, and entries will be emitted while uncompressing one after one another, while that of gzip is slightly different: gzip.UncompressStream is a transform stream, so no `entry` event will be emitted and you can just pipe to another stream**\n\nThis constrants is brought by Gzip algorithm itself, it only support compressing one file and uncompress one file.\n\n```js\nnew compressing.gzip.UncompressStream({ source: 'file/path/to/uncompress.gz' })\n  .on('error', handleError)\n  .pipe(fs.createWriteStream('path/to/dest/file'))\n  .on('error', handleError);\n```\n\n## API\n\n### compressFile\n\nUse this API to compress a single file. This is a convenient method, which wraps FileStream API below, but you can handle error in one place.\n\n- gzip.compressFile(source, dest, opts)\n- tar.compressFile(source, dest, opts)\n- tgz.compressFile(source, dest, opts)\n- zip.compressFile(source, dest, opts)\n\nParams\n\n- source {String|Buffer|Stream} - source to be compressed, could be a file path, buffer, or a readable stream\n- dest {String|Stream} - compressing destination, could be a file path(eg. `/path/to/xx.tgz`), or a writable stream.\n- opts {Object} - usually you don't need it\n\nReturns a promise object.\n\n### compressDir\n\nUse this API to compress a dir. This is a convenient method, which wraps Stream API below, but you can handle error in one place.\n\n__Note: gzip do not have a compressDir method, you may need tgz instead.__\n\n- tar.compressDir(source, dest, opts)\n- tgz.compressDir(source, dest, opts)\n- zip.compressDir(source, dest, opts)\n\nParams\n\n- source {String|Buffer|Stream} - source to be compressed\n- dest {String|Stream} - compressing destination, could be a file path(eg. `/path/to/xx.tgz`), or a writable stream.\n- opts {Object} - usually you don't need it\n\n### uncompress\n\nUse this API to uncompress a file. This is a convenient method, which wraps UncompressStream API below, but you can handle error in one place. RECOMMANDED.\n\n- tar.uncompress(source, dest, opts)\n- tgz.uncompress(source, dest, opts)\n- zip.uncompress(source, dest, opts)\n- gzip.uncompress(source, dest, opts)\n\nParams\n\n- source {String|Buffer|Stream} - source to be uncompressed\n- dest {String|Stream} - uncompressing destination. When uncompressing tar, tgz and zip, it should be a directory path (eg. `/path/to/xx`). **When uncompressing gzip, it should be a file path or a writable stream.**\n- opts {Object} - usually you don't need it\n  - opts.zipFileNameEncoding {String} - Only work on zip format, default is 'utf8'.\n    Major non-UTF8 encodings by languages:\n\n    - Korean: cp949, euc-kr\n    - Japanese: sjis (shift_jis), cp932, euc-jp\n    - Chinese: gbk, gb18030, gb2312, cp936, hkscs, big5, cp950\n\n### FileStream\n\nThe transform stream to compress a single file.\n\n__Note: If you are not very familiar with streams, just use compressFile() API, error can be handled in one place.__\n\n- new gzip.FileStream(opts)\n- new tar.FileStream(opts)\n- new tgz.FileStream(opts)\n- new zip.FileStream(opts)\n\nCommon params:\n\n- opts.source {String|Buffer|Stream} - source to be compressed, could be a file path, buffer, or a readable stream.\n\nGzip params:\n\n- opts.zlib - {Object} gzip.FileStream uses zlib to compress, pass this param to control the behavior of zlib.\n\nTar params:\n\n- opts.relativePath {String} - Adds a file from source into the compressed result file as opts.relativePath. Uncompression programs would extract the file from the compressed file as relativePath. If opts.source is a file path, opts.relativePath is optional, otherwise it's required.\n- opts.size {Number} - Tar compression requires the size of file in advance. When opts.source is a stream, the size of it cannot be calculated unless load all content of the stream into memory(the default behavior, but loading all data into memory could be a very bad idea). Pass opts.size to avoid loading all data into memory, or a warning will be shown.\n- opts.suppressSizeWarning {Boolean} - Pass true to suppress the size warning mentioned.\n\nTgz params:\n\ntgz.FileStream is a combination of tar.FileStream and gzip.FileStream, so the params are the combination of params of tar and gzip.\n\nZip params:\n\n- opts.relativePath {String} - Adds a file from source into the compressed result file as opts.relativePath. Uncompression programs would extract the file from the compressed file as relativePath. If opts.source is a file path, opts.relativePath is optional, otherwise it's required.\n- opts.yazl {Object} - zip.FileStream compression uses [yazl](https://github.com/thejoshwolfe/yazl), pass this param to control the behavior of yazl.\n\n### Stream\n\nThe readable stream to compress anything as you need.\n\n__Note: If you are not very familiar with streams, just use compressFile() and compressDir() API, error can be handled in one place.__\n\n__Gzip only support compressing a single file. So gzip.Stream is not available.__\n\n__Constructor__\n\n- new tar.Stream()\n- new tgz.Stream()\n- new zip.Stream()\n\nNo options in all constructors.\n\n__Instance methods__\n\n- addEntry(entry, opts)\n\nParams\n\n- entry {String|Buffer|Stream} - entry to compress, cound be a file path, a dir path, a buffer, or a stream.\n- opts.relativePath {String} - uncompression programs would extract the file from the compressed file as opts.relativePath. If entry is a file path or a dir path, opts.relativePath is optional, otherwise it's required.\n- opts.ignoreBase {Boolean} - when entry is a dir path, and opts.ignoreBase is set to true, the compression will contain files relative to the path passed, and not with the path included.\n\n### UncompressStream\n\nThe writable stream to uncompress anything as you need.\n\n__Note: If you are not very familiar with streams, just use `uncompress()` API, error can be handled in one place.__\n\n__Gzip only support compressing and uncompressing one single file. So gzip.UncompressStream is a transform stream which is different from others.__\n\n__Constructor__\n\n- new gzip.UncompressStream(opts)\n- new tar.UncompressStream(opts)\n- new tgz.UncompressStream(opts)\n- new zip.UncompressStream(opts)\n\nCommon params:\n\n- opts.source {String|Buffer|Stream} - source to be uncompressed, could be a file path, buffer, or a readable stream.\n\n__CAUTION for zip.UncompressStream__\n\nDue to the design of the .zip file format, it's impossible to interpret a .zip file without loading all data into memory.\n\nAlthough the API is streaming style(try to keep it handy), it still loads all data into memory.\n\nhttps://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api\n","readmeFilename":"README.md"}