Skip to content

Streams

C# TypeJS Type
Stream (read/write)Duplex
Stream (read-only)Readable
Stream (write-only)Writable

A .NET Stream instance is marshalled to and from Node.js Duplex, Readable, or Writable, depending whether the stream supports reading and/or writing. JS code can seamlessly read from or write to streams created by .NET, or .NET code can read from or write to streams created by JS. Streamed data is transferred using shared memory (without any additional sockets or pipes), so memory allocation and copying is minimized.

C#
[JSExport]
public static class Example
{
    public Stream GetContent() { … }
}
JS
const stream = Example.getContent();
stream.on('data', (chunk) => { console.log(chunk.toString()); });

The NodeStream class provides the .NET Stream adapter over a Node.js Duplex, Readable, or Writable stream.

Released under the MIT license