Monday, 12 June 2017

read ReadStream multiple times

I have a ReadStream that I wanna read multiple times.

First time I'm using it to get it's md5 hash, I'm doing it with module hasha.fromStream, and the second time I'm using it with FormData to upload a file to web hosting.

How can I use this one ReadStream to do both of these things?

hash = await hasha.fromStream(readStream, hashOptions);
readStream.on("data", (chunk) => console.log("data chunk", chunk)).on("end", () => console.log("finished"));

It's not loging the content to the console as it should, probably because in the hasha.fromStream it's pipe-ing the results. If I don't execute hasha.fromStream it's working fine, the chunks are logged.

The module I'm using, called hasha is on github: https://github.com/sindresorhus/hasha/blob/master/index.js#L45



via xerq

No comments:

Post a Comment