{"name":"compressing","version":"2.0.0","keywords":["compress","uncompress","util","tgz","gzip","tar","zip","stream"],"author":{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com"},"license":"MIT","_id":"compressing@2.0.0","maintainers":[{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"}],"homepage":"https://github.com/node-modules/compressing#readme","bugs":{"url":"https://github.com/node-modules/compressing/issues"},"dist":{"shasum":"d84ae8f77e502da2b860dc4aa7c8800e7dcfe5ac","tarball":"http://registry-npm.ywwl.com/compressing/download/compressing-2.0.0.tgz","fileCount":23,"integrity":"sha512-hRG5wpuy/lkO/oO8AEhSmLw2FVJOs2DnFPtmm0XUVWoDP6k3HAw5RVgyzbbATl0ytjJDCY03DvRiyjHkSHc1Dg==","signatures":[{"sig":"MEYCIQDT7JEmYBdwPSx1M8f1+WTiLdP1YKa9gfgIz7VU87nhuAIhANgeN2EbrGSpIJ8qPMImzVrZvKoP4SM3l5sX5bPcekXy","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/compressing@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":51643,"size":11363,"noattachment":false,"key":"/compressing/-/compressing-2.0.0.tgz"},"main":"index.js","engines":{"node":">= 18.0.0"},"gitHead":"b2d231b3096450962bd5673a436011c2d9828d56","scripts":{"ci":"npm run lint && npm run test:ts && npm run cov","cov":"egg-bin cov --ts false","lint":"eslint .","test":"npm run test:js && npm run test:ts","test:js":"egg-bin test --ts false","test:ts":"tsc -p ./test/fixtures/types/tsconfig.json","lint-fix":"eslint . --fix"},"typings":"index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:aaa06b59-7474-4c7d-929b-08f4dcbc4ed4"}},"repository":{"url":"git+https://github.com/node-modules/compressing.git","type":"git"},"_npmVersion":"11.5.2","description":"Everything you need for compressing and uncompressing","directories":{},"_nodeVersion":"22.18.0","dependencies":{"yazl":"^2.4.2","get-ready":"^1.0.0","iconv-lite":"^0.5.0","tar-stream":"^1.5.2","streamifier":"^0.1.1","@eggjs/yauzl":"^2.11.0","flushwritable":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"mm":"^2.0.0","uuid":"^3.0.1","eslint":"8","egg-bin":"6","mz-modules":"^2.1.0","typescript":"5","@types/node":"20","dir-compare":"^1.3.0","@types/mocha":"10","eslint-config-egg":"12"},"_npmOperationalInternal":{"tmp":"tmp/compressing_2.0.0_1754740291306_0.4287865218827598","host":"s3://npm-registry-packages-npm-production"},"readme":"# compressing\n\n[![NPM version][npm-image]][npm-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/compressing.svg?style=flat)](https://nodejs.org/en/download/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/node-modules/compressing)\n\n[npm-image]: https://img.shields.io/npm/v/compressing.svg?style=flat-square\n[npm-url]: https://npmx.dev/package/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[download-image]: https://img.shields.io/npm/dm/compressing.svg?style=flat-square\n[download-url]: https://npmx.dev/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 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('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('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 { pipeline: pump } = require('stream');\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### 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('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('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('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\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('compressing');\n\nurllib.request('http://registry.npmjs.org/compressing/-/compressing-2.0.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('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    fs.mkdir(path.join(destDir, header.name), { recursive: true }, 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  - opts.strip {Number} - Strip leading path segments when extracting (tar/tgz/zip). Default is 0.\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- opts.strip {Number} - Strip leading path segments when extracting (tar/tgz/zip). Default is 0.\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\n<https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api>\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/compressing)](https://github.com/node-modules/compressing/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1754740291518,"_cnpm_publish_time":1754740291518,"dist-tags":{"latest":"2.1.5","release-1.x":"1.10.6"}}