{"name":"modern-tar","version":"0.4.2","author":{"name":"Ayuhito","email":"hello@ayuhito.com"},"license":"MIT","_id":"modern-tar@0.4.2","maintainers":[{"name":"lotusdevshack","email":"declininglotus@gmail.com"}],"homepage":"https://github.com/ayuhito/modern-tar","bugs":{"url":"https://github.com/ayuhito/modern-tar/issues"},"dist":{"shasum":"a6d96e6d640b8f856f4f792cdf9de99231860b1a","tarball":"http://registry-npm.ywwl.com/modern-tar/download/modern-tar-0.4.2.tgz","fileCount":9,"integrity":"sha512-YYqHOpiRBK3o7H4Cze9b/OQoys9T0+B3YM3ShzekDiv0Qo744OFPXailNzVfjSKbDSIduDCCcr3I6Y0LEfYtXA==","signatures":[{"sig":"MEYCIQD8jl+CoREqQsLImlxr5Y3jzrIYHK4b/UQcY39b7WbG+gIhAJF3gRM1pBZqMCA2C9PLlJUYUj8h9KviHi4uFmqvkmSD","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/modern-tar@0.4.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":72255,"size":19046,"noattachment":false,"key":"/modern-tar/-/modern-tar-0.4.2.tgz"},"main":"./dist/web/index.js","type":"module","types":"./dist/web/index.d.ts","module":"./dist/web/index.js","engines":{"node":">=18.0.0"},"exports":{".":"./dist/web/index.js","./fs":"./dist/fs/index.js","./package.json":"./package.json"},"gitHead":"8ab5650ac50912d30d988366b37f5d7b327a0963","scripts":{"dev":"tsdown --watch","test":"vitest","build":"tsdown","check":"biome check --write","coverage":"vitest run --coverage","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7d53381c-e2dc-4005-8fb7-f849fa81e1b4"}},"repository":{"url":"git+https://github.com/ayuhito/modern-tar.git","type":"git"},"_npmVersion":"11.6.2","description":"Zero dependency streaming tar parser and writer for JavaScript.","directories":{},"sideEffects":false,"_nodeVersion":"24.9.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.15.6","vitest":"^3.2.4","typescript":"^5.9.3","@types/node":"^24.7.1","@biomejs/biome":"2.2.5","@vitest/coverage-v8":"^3.2.4"},"_npmOperationalInternal":{"tmp":"tmp/modern-tar_0.4.2_1760153548561_0.14439443138577146","host":"s3://npm-registry-packages-npm-production"},"readme":"# 🗄️ modern-tar\n\nZero-dependency, cross-platform, streaming tar archive library for every JavaScript runtime. Built with the browser-native Web Streams API for performance and memory efficiency.\n\n## Features\n\n- 🚀 **Streaming Architecture** - Supports large archives without loading everything into memory.\n- 📋 **Standards Compliant** - Full USTAR format support with PAX extensions. Compatible with GNU tar, BSD tar, and other standard implementations.\n- 🗜️ **Compression** - Supports gzip compression and decompression with native compression streams.\n- 📝 **TypeScript First** - Full type safety with detailed TypeDoc documentation.\n- ⚡ **Zero Dependencies** - No external dependencies, minimal bundle size.\n- 🌐 **Cross-Platform** - Works in browsers, Node.js, Cloudflare Workers, and other JavaScript runtimes.\n- 📁 **Node.js Integration** - Additional high-level APIs for directory packing and extraction.\n\n## Installation\n\n```sh\nnpm install modern-tar\n```\n\n## Usage\n\nThis package provides two entry points:\n\n- `modern-tar`: The core, cross-platform streaming API (works everywhere).\n- `modern-tar/fs`: High-level filesystem utilities for Node.js.\n\n### Core Usage\n\nThese APIs use the Web Streams API and can be used in any modern JavaScript environment.\n\n#### Simple\n\n```typescript\nimport { packTar, unpackTar } from 'modern-tar';\n\n// Entry bodies can be strings, bytes, Blobs, or ReadableStreams.\nconst archive = await packTar([\n\t{ header: { name: \"file.txt\", size: 5 }, body: \"hello\" },\n\t{ header: { name: \"dir/\", type: \"directory\", size: 0 } },\n\t{ header: { name: \"dir/nested.txt\", size: 3 }, body: new Uint8Array([97, 98, 99]) } // \"abc\"\n]);\n\n// Unpack tar buffer into entries\nconst extracted = await unpackTar(archive);\nconst decoder = new TextDecoder();\n\nfor (const { header, data } of extracted) {\n\tif (data) {\n\t\tconsole.log(`${header.name}: ${decoder.decode(data)}`);\n\t} else {\n\t\tconsole.log(`${header.type}: ${header.name}`);\n\t}\n}\n```\n\n#### Streaming\n\n```typescript\nimport { createTarDecoder } from 'modern-tar';\n\nconst response = await fetch('/archive.tar');\nif (!response.ok) throw new Error(`Download failed: ${response.status}`);\nif (!response.body) throw new Error('No response body');\n\nconst entries = response.body.pipeThrough(createTarDecoder());\nfor await (const entry of entries) {\n\tif (!entry.header.name.endsWith(\".txt\")) {\n\t\t// You MUST read each entry body completely before advancing.\n\t\t// If an entry is not needed, cancel its body so the stream does not stall.\n\t\tawait entry.body.cancel();\n\t\tcontinue;\n\t}\n\n\tconst text = await new Response(entry.body).text();\n\tconsole.log(`${entry.header.name}: ${text}`);\n}\n```\n\n#### Compression/Decompression (gzip)\n\n```typescript\nimport { createTarPacker } from 'modern-tar';\n\nconst { readable, controller } = createTarPacker();\nconst gzipResponse = new Response(\n  readable.pipeThrough(new CompressionStream('gzip')),\n  { headers: { 'Content-Type': 'application/gzip' } }\n);\n\nconst body = controller.add({ name: 'hello.txt', size: 5 });\nconst writer = body.getWriter();\nawait writer.write(new TextEncoder().encode('hello'));\nawait writer.close();\ncontroller.finalize();\n\n// Return gzipResponse from your server or Worker handler.\n```\n\n```typescript\nimport { unpackTar } from 'modern-tar';\n\n// Download and unpack a .tar.gz without buffering the compressed archive\nconst response = await fetch('https://api.example.com/archive.tar.gz');\nif (!response.ok) throw new Error(`Download failed: ${response.status}`);\nif (!response.body) throw new Error('No response body');\n\nconst entries = await unpackTar(\n  response.body.pipeThrough(new DecompressionStream('gzip'))\n);\nconst decoder = new TextDecoder();\n\nfor (const { header, data } of entries) {\n  if (data) {\n    console.log(`${header.name}: ${decoder.decode(data)}`);\n  }\n}\n```\n\n### Node.js Filesystem Usage\n\nThese APIs use Node.js streams when interacting with the local filesystem.\n\n#### Simple\n\n```typescript\nimport { packTar, unpackTar } from 'modern-tar/fs';\nimport { createWriteStream, createReadStream } from 'node:fs';\nimport { pipeline } from 'node:stream/promises';\n\n// Pack a directory into a tar file\nconst tarStream = packTar('./my/project');\nconst fileStream = createWriteStream('./project.tar');\nawait pipeline(tarStream, fileStream);\n\n// Extract a tar file to a directory\nconst tarReadStream = createReadStream('./project.tar', {\n\thighWaterMark: 256 * 1024 // 256 KB for optimal performance\n});\nconst extractStream = unpackTar('./output/directory');\nawait pipeline(tarReadStream, extractStream);\n```\n\n#### Filtering and Transformation\n\n```typescript\nimport { packTar, unpackTar } from 'modern-tar/fs';\nimport { createReadStream } from 'node:fs';\nimport { pipeline } from 'node:stream/promises';\n\n// Pack with filtering\nconst packStream = packTar('./my/project', {\n\tfilter: (filePath, stats) => !filePath.includes('node_modules'),\n\tmap: (header) => ({ ...header, mode: 0o644 }), // Set all files to 644\n\tdereference: true // Follow symlinks instead of archiving them\n});\n\n// Unpack with advanced options\nconst sourceStream = createReadStream('./archive.tar', {\n\thighWaterMark: 256 * 1024 // 256 KB for optimal performance\n});\nconst extractStream = unpackTar('./output', {\n\t// Core options\n\tstrip: 1, // Remove first directory level\n\tfilter: (header) => header.name.endsWith('.js'), // Only extract JS files\n\tmap: (header) => ({ ...header, name: header.name.toLowerCase() }), // Transform names\n\n\t// Filesystem-specific options\n\tfmode: 0o644, // Override file permissions\n\tdmode: 0o755, // Override directory permissions\n\tmaxDepth: 50,  // Limit extraction depth for security (default: 1024)\n\tconcurrency: 8 // Limit concurrent filesystem operations (default: CPU cores)\n});\n\nawait pipeline(sourceStream, extractStream);\n```\n\n#### Archive Creation\n\n```typescript\nimport { packTar, type TarSource } from 'modern-tar/fs';\nimport { createWriteStream } from 'node:fs';\nimport { pipeline } from 'node:stream/promises';\n\n// Pack multiple sources\nconst sources: TarSource[] = [\n  { type: 'file', source: './package.json', target: 'project/package.json' },\n  { type: 'directory', source: './src', target: 'project/src' },\n  { type: 'content', content: 'Hello World!', target: 'project/hello.txt' },\n  { type: 'content', content: '#!/bin/bash\\necho \"Executable\"', target: 'bin/script.sh', mode: 0o755 },\n  { type: 'stream', content: createReadStream('./large-file.bin'), target: 'project/data.bin', size: 1048576 },\n  { type: 'stream', content: fetch('/api/data').then(r => r.body!), target: 'project/remote.json', size: 2048 }\n];\n\nconst archiveStream = packTar(sources);\nawait pipeline(archiveStream, createWriteStream('project.tar'));\n```\n\n#### Compression/Decompression (gzip)\n\n```typescript\nimport { packTar, unpackTar } from 'modern-tar/fs';\nimport { createWriteStream, createReadStream } from 'node:fs';\nimport { createGzip, createGunzip } from 'node:zlib';\nimport { pipeline } from 'node:stream/promises';\n\n// Pack directory and compress to .tar.gz\nconst tarStream = packTar('./my/project');\nawait pipeline(tarStream, createGzip(), createWriteStream('./project.tar.gz'));\n\n// Decompress and extract .tar.gz\nconst gzipStream = createReadStream('./project.tar.gz', {\n\thighWaterMark: 256 * 1024 // 256 KB for optimal performance\n});\nawait pipeline(gzipStream, createGunzip(), unpackTar('./output'));\n```\n\n## API Reference\n\nSee the [API Reference](./REFERENCE.md).\n\n# Benchmarks\n\nCurrent benchmarks indicate we're much faster than other popular tar libraries for small file archives (packing and unpacking). On the other hand, larger files hit an I/O bottleneck resulting in similar performance between libraries.\n\nSee the [Results](./benchmarks/README.md).\n\n## Compatibility\n\nThe core library uses the [Web Streams API](https://caniuse.com/streams) and requires:\n\n- **Node.js**: 18.0+\n- **TypeScript**: 5.7+ when consuming the bundled declarations\n- **Browsers**: Baseline Widely available\n  - Chrome 85+\n  - Edge 85+\n  - Firefox 102+\n  - Safari 14.1+\n\nIf you use `CompressionStream` or `DecompressionStream`, Firefox 113+ and\nSafari 16.4+ are required.\n\n## Acknowledgements\n\n- [`tar-stream`](https://github.com/mafintosh/tar-stream) and [`tar-fs`](https://github.com/mafintosh/tar-fs) - For the inspiration and test fixtures.\n\n## License\n\nMIT\n","publish_time":1760153548732,"_cnpm_publish_time":1760153548732,"dist-tags":{"latest":"0.8.6"}}