Git Product home page Git Product logo

Comments (2)

dubiousjim avatar dubiousjim commented on May 30, 2024

I was just looking at this part of your code, and was considering this question. I came to the conclusion there would be no benefit. You create a Node stream with createWriteStream but then immediately async iterate over it (using yield *). Adding the stream.Readable.toWeb wrapper there would just be overhead that got immediately discarded.

A more aggressive change might be to change BlobDataItem.prototype.stream from being an async generator to returning a web stream. But since BlobDataItem is an internal class, I don't see what the benefit in doing that would be, either.

from fetch-blob.

jimmywarting avatar jimmywarting commented on May 30, 2024

yup, it will just be unnecessary overhead.
the better solution would be to wait for nodejs/node#40606 to be fixed so it would be possible to go direct from file to whatwg stream, the extra overhead of converting it to buffer/node:stream/iterator/uint8array is not worth it...

the best solution would be to get rid of the toIterator entirely so that it never touches the main thread so that we could do something like this instead:

function concatenateReadables(readables) {
  const ts = new TransformStream();
  let promise = Promise.resolve();

  for (const readable of readables) {
    promise = promise.then(
     () => readable.pipeTo(ts.writable, { preventClose: true }),
     reason => {
       return Promise.all([
         ts.writable.abort(reason),
         readable.cancel(reason)
       ]);
     }
   );
  }

  promise.then(() => ts.writable.close(),
               reason => ts.writable.abort(reason))
         .catch(() => {});

  return ts.readable;
}

ref: https://streams.spec.whatwg.org/#example-identity-transform-usages

from fetch-blob.

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.