{"_id":"tar-stream@3.2.2","bugs":{"url":"https://github.com/mafintosh/tar-stream/issues"},"dist":{"shasum":"aec7f257e712192a177a93aa0450c2e76855c8be","tarball":"http://registry-npm.ywwl.com/tar-stream/download/tar-stream-3.2.2.tgz","fileCount":9,"integrity":"sha512-+8NeqHRjQWH9nYlwo2gamAMImZCVzI4UoEgDpWorBt9OEfppiZn+uSkskzQKPWIZyji/C8fpWO7u69G0DX0tbg==","signatures":[{"sig":"MEYCIQCt5h/RFJCH2PpKhNA89vOYsjlfqJZ9hPCAVbCiao0ufAIhAPGHzI8ADQ1y+PdGuk1ACpba3AmfngXpa3tc+PRKDix1","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDR9VFQ5oDINEXjaafARiKnuiZ7TJ9D1uxZDWxdgkleLAIhAKw6Ei/ENy05O4QEaaAzp13VyfUTS4zJQzlQ2m+fkjLJ"}],"unpackedSize":34003,"size":10375,"noattachment":false,"key":"/tar-stream/-/tar-stream-3.2.2.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":"d49f05b495b432d57042d461bd91036b58439c6a","imports":{"fs":{"bare":"bare-fs","default":"fs"}},"license":"MIT","scripts":{"test":"standard && brittle-node test/*.js"},"version":"3.2.2","_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.9.0","bare-fs":"^4.8.2","streamx":"^2.28.1","fast-fifo":"^1.3.2"},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^4.3.0","standard":"^17.0.1","concat-stream":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tar-stream_3.2.2_1790958793146_0.9703960928213535"},"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":1790958793226,"_cnpm_publish_time":1790958793226,"dist-tags":{"latest":"3.3.0"}}