hypercore icon indicating copy to clipboard operation
hypercore copied to clipboard

pipe hypercore.replicate from webReadableStream to webWritableStream

Open sce9sc opened this issue 2 years ago • 1 comments

First of all , It is the most amazing project I have ever come across.

I was wondering how can I pipe the hypercore.replicate stream which is a duplex Node.js stream to a webReabable and a webWritable streams in the browser.

I have two distinct streams . A webReadable and a webWritable . Since there is no duplex stream for web does anyone know how to do it or at least point me to the right direction.

Thank you in advance.

sce9sc avatar Nov 04 '22 16:11 sce9sc

In node I have accomplished as shown below:

 const { ReadableStream, WritableStream } = require('node:stream/web');
 const streamNode = require('node:stream');

  session.ReadableStream = ReadableStream;
  session.WritableStream = WritableStream;
  let duplex = streamNode.Duplex.fromWeb({
    readable: session.getReadableStream(),
    writable: session.getWritableStream(),
  });

const repStream = core.replicate(true,{ keepAlive: false})
  duplex.pipe(repStream).pipe(duplex)

sce9sc avatar Nov 04 '22 16:11 sce9sc