Giter Club home page Giter Club logo

Comments (8)

mafintosh avatar mafintosh commented on August 12, 2024 3

We just need a streamx -> browser stream general module. prop not too hard :)

from tar-stream.

luiscastro193 avatar luiscastro193 commented on August 12, 2024 1

In the meantime, I recommend using https://www.npmjs.com/package/readable-web-to-node-stream and https://www.npmjs.com/package/readable-stream-node-to-web

from tar-stream.

piranna avatar piranna commented on August 12, 2024 1

There's Native support for WebStreams un Node.js, we should use them instead of third-party modules.

from tar-stream.

mafintosh avatar mafintosh commented on August 12, 2024

don't know much about browser streams, but if you share some docs on them, mb we can make a wrapper

from tar-stream.

vritant24 avatar vritant24 commented on August 12, 2024

https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Concepts

MDN has the docs for readable streams. unfortunately I'm a little less versed on these as well, but happy to help implement them @mafintosh

from tar-stream.

gchartier avatar gchartier commented on August 12, 2024

Any update on this? I have the exact same need / problem

from tar-stream.

luiscastro193 avatar luiscastro193 commented on August 12, 2024

+1 on this

from tar-stream.

maxpatiiuk avatar maxpatiiuk commented on August 12, 2024

readable-web-to-node-stream appears to no longer be maintained, and fails to build in Webpack for me. I was able to use @smessie/readable-web-to-node-stream instead

Example code

Install dependencies:

npm i tar-stream @smessie/readable-web-to-node-stream
npm i -D @types/tar-stream

Content script:

const worker = new Worker('worker.js');

// User picks a file - we convert the file to a stream, and give it to a web worker:
const fileStream = file.stream();
worker.postMessage({ fileStream }, [fileStream]);

Web worker:

import { ReadableWebToNodeStream } from '@smessie/readable-web-to-node-stream';
import type { Readable } from 'node:stream';
import tar from 'tar-stream';

self.addEventListener('message', async (event) => {
  const fileStream: ReadableStream<Uint8Array> = event.data.fileStream;
  const decompressionStream = new DecompressionStream('gzip');
  const decompressedStream = fileStream.pipeThrough(decompressionStream);
  const extract = tar.extract();
  const nodeStream = new ReadableWebToNodeStream(decompressedStream) as unknown as Readable;
  nodeStream.pipe(extract);
  for await (const entry of extract) {
    console.log(entry.header.type, entry.header.name)
    entry.resume();
  }
});

from tar-stream.

Related Issues (20)

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.