2

All of the examples of stream creation I have encountered are centered around file. I am working with an interface that requires me to pipe a read stream to a write stream. My input is raw bytes I have in memory, not a file.

https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options

How to accomplish ^^^ by passing in 'raw bytes' instead of a file descriptor?

Robert Christian
  • 18,218
  • 20
  • 74
  • 89

1 Answers1

3

This is what I got working (from How to create streams from string in Node.Js?):

streamFromString(raw) {
    const Readable = require('stream').Readable;
    const s = new Readable();
    s._read = function noop() {};
    s.push(raw);
    s.push(null);
    return s;
  }
Robert Christian
  • 18,218
  • 20
  • 74
  • 89