admin管理员组

文章数量:1323317

The internal library which I'm using is providing NodeJS.ReadableStream, which I need to pass to nodemailer (attachments), which is taking as parameter Readable.

 Argument of type 'Buffer | ReadableStream' is not assignable to parameter of type 'Buffer | Readable'.
  Type 'ReadableStream' is not assignable to type 'Buffer | Readable'.


Resolved. Created Readable instance, and used .wrap method for ReadableStream

The internal library which I'm using is providing NodeJS.ReadableStream, which I need to pass to nodemailer (attachments), which is taking as parameter Readable.

 Argument of type 'Buffer | ReadableStream' is not assignable to parameter of type 'Buffer | Readable'.
  Type 'ReadableStream' is not assignable to type 'Buffer | Readable'.


Resolved. Created Readable instance, and used .wrap method for ReadableStream

Share edited Jul 11, 2019 at 8:47 hejkerooo asked Jul 11, 2019 at 8:16 hejkerooohejkerooo 7873 gold badges8 silver badges22 bronze badges 2
  • 2 Thank you very much for sharing! Link to node doc: nodejs/api/stream.html#stream_readable_wrap_stream – Huan Commented Jun 27, 2020 at 11:37
  • See my answer on duplicate question: stackoverflow./questions/71509505/… – Mikael Couzic Commented Jul 15, 2024 at 11:59
Add a ment  | 

1 Answer 1

Reset to default 4

Posting the solution provided from @hejkerooo as an answer:

const { OldReader } = require('./old-api-module.js'); 
const { Readable } = require('node:stream');
const oreader = new OldReader(); // ReadableStream
const myReader = new Readable().wrap(oreader); // Readable

Source: https://nodejs/api/stream.html#readablewrapstream

本文标签: javascriptHow to cast ReadableStream to ReadableStack Overflow