{"_id":"tar-stream@3.2.1","bugs":{"url":"https://github.com/mafintosh/tar-stream/issues"},"dist":{"shasum":"952d72f7aba68ce5cb802ef2e0b19f1bd989140d","tarball":"http://registry-npm.ywwl.com/tar-stream/download/tar-stream-3.2.1.tgz","fileCount":9,"integrity":"sha512-nqsEO8zLZJvrOMdEwkA0QdCLFbetHMn95Zqu4fKwX+hkaTWJPZZOrxx/PwtxoK0MMGQmBQNRW3CPs8IFYQz4cQ==","signatures":[{"sig":"MEQCIGzDqctgeH9DJ7RAIpbgwcTlL2zHLa1moyIYXMSu7/kJAiAmyxXalbvQTuFsRt5tjWlzeJ1AwJFke8Re+Gugmo5FCQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDULAXEeU8NSAS4HcARitogRK+sBvIzIC951mFdMa02DAiAlRQv8SPxba317f06LU5n2y9r9i3/TCXcdcekuz7f84g=="}],"unpackedSize":33998,"size":10381,"noattachment":false,"key":"/tar-stream/-/tar-stream-3.2.1.tgz"},"main":"index.js","name":"tar-stream","types":"./index.d.ts","author":{"name":"Mathias Buus","email":"mathiasbuus@gmail.com"},"browser":{"fs":false},"exports":{".":{"types":"./index.d.ts","default":"./index.js"},"./package":"./package.json"},"gitHead":"246572f479d92b0748b21c873e58c64a84a0b826","imports":{"fs":{"bare":"bare-fs","default":"fs"}},"license":"MIT","scripts":{"test":"standard && brittle test/*.js"},"version":"3.2.1","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"homepage":"https://github.com/mafintosh/tar-stream","repository":{"url":"git+https://github.com/mafintosh/tar-stream.git","type":"git"},"_npmVersion":"11.15.0","description":"tar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.","directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_nodeVersion":"24.13.0","dependencies":{"b4a":"^1.6.4","bare-fs":"^4.5.5","streamx":"^2.15.0","fast-fifo":"^1.2.0"},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.3.2","standard":"^17.0.1","concat-stream":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tar-stream_3.2.1_1787672124107_0.43091793678636003"},"readme":"# tar-stream\n\ntar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.\n\nNote that you still need to gunzip your data if you have a `.tar.gz`. We recommend using [gunzip-maybe](https://github.com/mafintosh/gunzip-maybe) in conjunction with this.\n\n```\nnpm install tar-stream\n```\n\n[![build status](https://secure.travis-ci.org/mafintosh/tar-stream.png)](http://travis-ci.org/mafintosh/tar-stream)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)\n\n## Usage\n\ntar-stream exposes two streams, [pack](https://github.com/mafintosh/tar-stream#packing) which creates tarballs and [extract](https://github.com/mafintosh/tar-stream#extracting) which extracts tarballs. To [modify an existing tarball](https://github.com/mafintosh/tar-stream#modifying-existing-tarballs) use both.\n\n\nIt implementes USTAR with additional support for pax extended headers. It should be compatible with all popular tar distributions out there (gnutar, bsdtar etc)\n\n## Related\n\nIf you want to pack/unpack directories on the file system check out [tar-fs](https://github.com/mafintosh/tar-fs) which provides file system bindings to this module.\n\n## Packing\n\nTo create a pack stream use `tar.pack()` and call `pack.entry(header, [callback])` to add tar entries.\n\n``` js\nconst tar = require('tar-stream')\nconst pack = tar.pack() // pack is a stream\n\n// add a file called my-test.txt with the content \"Hello World!\"\npack.entry({ name: 'my-test.txt' }, 'Hello World!')\n\n// add a file called my-stream-test.txt from a stream\nconst entry = pack.entry({ name: 'my-stream-test.txt', size: 11 }, function(err) {\n  // the stream was added\n  // no more entries\n  pack.finalize()\n})\n\nentry.write('hello')\nentry.write(' ')\nentry.write('world')\nentry.end()\n\n// pipe the pack stream somewhere\npack.pipe(process.stdout)\n```\n\n## Extracting\n\nTo extract a stream use `tar.extract()` and listen for `extract.on('entry', (header, stream, next) )`\n\n``` js\nconst extract = tar.extract()\n\nextract.on('entry', function (header, stream, next) {\n  // header is the tar header\n  // stream is the content body (might be an empty stream)\n  // call next when you are done with this entry\n\n  stream.on('end', function () {\n    next() // ready for next entry\n  })\n\n  stream.resume() // just auto drain the stream\n})\n\nextract.on('finish', function () {\n  // all entries read\n})\n\npack.pipe(extract)\n```\n\nThe tar archive is streamed sequentially, meaning you **must** drain each entry's stream as you get them or else the main extract stream will receive backpressure and stop reading.\n\n## Extracting as an async iterator\n\nThe extraction stream in addition to being a writable stream is also an async iterator\n\n``` js\nconst extract = tar.extract()\n\nsomeStream.pipe(extract)\n\nfor await (const entry of extract) {\n  entry.header // the tar header\n  entry.resume() // the entry is the stream also\n}\n```\n\n## Headers\n\nThe header object using in `entry` should contain the following properties.\nMost of these values can be found by stat'ing a file.\n\n``` js\n{\n  name: 'path/to/this/entry.txt',\n  size: 1314,        // entry size. defaults to 0\n  mode: 0o644,       // entry mode. defaults to to 0o755 for dirs and 0o644 otherwise\n  mtime: new Date(), // last modified date for entry. defaults to now.\n  type: 'file',      // type of entry. defaults to file. can be:\n                     // file | link | symlink | directory | block-device\n                     // character-device | fifo | contiguous-file\n  linkname: 'path',  // linked file name\n  uid: 0,            // uid of entry owner. defaults to 0\n  gid: 0,            // gid of entry owner. defaults to 0\n  uname: 'maf',      // uname of entry owner. defaults to null\n  gname: 'staff',    // gname of entry owner. defaults to null\n  devmajor: 0,       // device major version. defaults to 0\n  devminor: 0        // device minor version. defaults to 0\n}\n```\n\n## Modifying existing tarballs\n\nUsing tar-stream it is easy to rewrite paths / change modes etc in an existing tarball.\n\n``` js\nconst extract = tar.extract()\nconst pack = tar.pack()\nconst path = require('path')\n\nextract.on('entry', function (header, stream, callback) {\n  // let's prefix all names with 'tmp'\n  header.name = path.join('tmp', header.name)\n  // write the new entry to the pack stream\n  stream.pipe(pack.entry(header, callback))\n})\n\nextract.on('finish', function () {\n  // all entries done - lets finalize it\n  pack.finalize()\n})\n\n// pipe the old tarball to the extractor\noldTarballStream.pipe(extract)\n\n// pipe the new tarball the another stream\npack.pipe(newTarballStream)\n```\n\n## Saving tarball to fs\n\n\n``` js\nconst fs = require('fs')\nconst tar = require('tar-stream')\n\nconst pack = tar.pack() // pack is a stream\nconst path = 'YourTarBall.tar'\nconst yourTarball = fs.createWriteStream(path)\n\n// add a file called YourFile.txt with the content \"Hello World!\"\npack.entry({ name: 'YourFile.txt' }, 'Hello World!', function (err) {\n  if (err) throw err\n  pack.finalize()\n})\n\n// pipe the pack stream to your file\npack.pipe(yourTarball)\n\nyourTarball.on('close', function () {\n  console.log(path + ' has been written')\n  fs.stat(path, function(err, stats) {\n    if (err) throw err\n    console.log(stats)\n    console.log('Got file info successfully!')\n  })\n})\n```\n\n## Performance\n\n[See tar-fs for a performance comparison with node-tar](https://github.com/mafintosh/tar-fs/blob/master/README.md#performance)\n\n# License\n\nMIT\n","publish_time":1787672124184,"_cnpm_publish_time":1787672124184,"dist-tags":{"latest":"3.3.0"}}