Answer the question
In order to leave comments, you need to log in
How to transform a stream from write to read?
Guys, I’ll say right away that I’m more on the front, so I’ll ask you not to throw tomatoes for ignorance.
In general, I can not solve such a problem related to flows.
The task is such that we download the file using request and then send this file to some API (this API accepts a read stream - ReadStream).
at the moment, the implementation looks roughly like this:
(does not suit that you need to create a temporary file)
request(audioLink)
.pipe(fs.createWriteStream(`./source/${fileName}`))
.on('close', function () {
ctx.replyWithVoice({
source: fs.createReadStream(`./source/${fileName}`)
})
})
Answer the question
In order to leave comments, you need to log in
it? https://www.npmjs.com/package/request-stream
In general, in theory, you can simply do
ctx.replyWithVoice({
source: request(audioLink)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question