GithubHelp home page GithubHelp logo

blackaslight / tar-stream Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 42 KB

A ustar format implementation of Tar based off the FreeBSD 15.0 spec.

Home Page: https://jsr.io/@doctor/tar-stream

License: MIT License

TypeScript 100.00%
browser deno javascript stream tar typescript untar

tar-stream's Introduction

Tar Stream

Tar Stream is an implementation made from scratch following the FreeBSD 15.0 spec.

File Format + Limitations

This implementation follows the ustar file format for creating and expanding Tarballs. While this format is compatible with most tar implementations, the format does have several limitations, including:

  • Pathnames cannot exceed 256 characters.
    • If the pathname exceeds 100 characters, it must be split-able on a forward slash / so each side does not exceed 155 and 100 characters respectively.
  • Files can't exceed a size of 64 GiBs.
    • If a file size exceeds 8 GiBs then the size extension will be automatically enabled allowing up to 64 GiBs per size, but this might exclude it from being expanded by older implementations of Tar that don't support the size extension.
  • Spares files are not supported.

Compression

Tar doesn't offer compression by default, so if you'd like to compress the Tarball, you may do so by piping it through a compression stream.

Example in creating a tarball.

import { type TarFile, TarStream } from '@doctor/tar-stream'

await ReadableStream.from(readDir('./'))
  .pipeThrough(
    new TransformStream<string, TarFile>({
      async transform(chunk, controller) {
        if (chunk.endsWith('.ts')) {
          controller.enqueue({
            pathname: chunk,
            size: (await Deno.stat(chunk)).size,
            iterable: (await Deno.open(chunk)).readable,
          })
        }
      },
    }),
  )
  .pipeThrough(new TarStream())
  .pipeThrough(new CompressionStream('gzip'))
  .pipeTo((await Deno.create('./archive.tar.gz')).writable)

async function* readDir(path: string): AsyncGenerator<string> {
  if (!path.endsWith('/')) {
    path += '/'
  }
  for await (const dirEntry of Deno.readDir(path)) {
    if (dirEntry.isFile) {
      yield path + dirEntry.name
    } else if (dirEntry.isDirectory) {
      for await (const filePath of readDir(path + dirEntry.name)) {
        yield filePath
      }
    }
  }
}

tar-stream's People

Contributors

blackaslight avatar david50407 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

david50407

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.