{"library":"modern-tar","title":"Modern Tar Archiver","description":"modern-tar is a zero-dependency, cross-platform JavaScript library designed for efficient streaming of tar archives. It supports both parsing and writing tar files, leveraging the browser-native Web Streams API for optimal performance and memory efficiency across diverse JavaScript runtimes, including Node.js (requiring version 18.0.0 or higher), web browsers, and Cloudflare Workers. The library is currently at stable version 0.7.6, with a consistent release cadence that introduces bug fixes, performance optimizations, and crucial security patches. Its key differentiators include a robust streaming architecture capable of handling large archives without full memory loading, full compliance with USTAR format and PAX extensions, built-in helpers for gzip compression, a TypeScript-first design ensuring strong type safety, and a minimal footprint due to its zero external dependencies.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install modern-tar"],"cli":null},"imports":["import { packTar } from 'modern-tar'","import { unpackTar } from 'modern-tar'","import { createTarPacker } from 'modern-tar'","import { createGzipEncoder } from 'modern-tar'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createTarPacker, createTarDecoder } from 'modern-tar';\n\nasync function processTarStream() {\n  // Create a tar packer\n  const { readable, controller } = createTarPacker();\n\n  // Add entries dynamically\n  const fileStream = controller.add({\n    name: \"dynamic.txt\",\n    size: 5,\n    type: \"file\"\n  });\n\n  // Write content to the stream\n  const writer = fileStream.getWriter();\n  await writer.write(new TextEncoder().encode(\"hello\"));\n  await writer.close();\n\n  // Add another entry, maybe a directory\n  controller.add({ name: \"my-dir/\", type: \"directory\", size: 0 });\n\n  // When done adding entries, finalize the archive\n  controller.finalize();\n\n  // Pipe the archive right into a decoder\n  const decodedStream = readable.pipeThrough(createTarDecoder());\n  for await (const entry of decodedStream) {\n    console.log(`Decoded: ${entry.header.name}`);\n\n    const shouldSkip = entry.header.name.endsWith(\".md\");\n    if (shouldSkip) {\n      // You MUST drain the body with cancel() to proceed to the next entry or read it fully,\n      // otherwise the stream will stall.\n      await entry.body.cancel();\n      continue;\n    }\n\n    // Example: Read the content for non-skipped files\n    if (entry.header.type === 'file') {\n      const reader = entry.body.getReader();\n      let chunk = '';\n      while (true) {\n        const { done, value } = await reader.read();\n        if (done) break;\n        chunk += new TextDecoder().decode(value);\n      }\n      console.log(`Content of ${entry.header.name}: ${chunk}`);\n    }\n  }\n  console.log('Tar stream processing complete.');\n}\n\nprocessTarStream().catch(console.error);","lang":"typescript","description":"Demonstrates streaming tar creation with `createTarPacker` and subsequent decoding with `createTarDecoder`, highlighting dynamic entry addition and the necessity of draining entry bodies.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}