nodejs създаване на поток
const { Readable } = require("stream")
const readable = Readable.from(["input string"])
readable.on("data", (chunk) => {
console.log(chunk) // will be called once with `"input string"`
})
файл за запис на поток nodejs
const readFile: InstanceType<typeof stream.Readable> = new stream.Readable({
read() {
return true
}
})
readFile
.pipe(fs.createWriteStream(`${process.env.IMG_DIR}/${Date.now().toString()}-${file.originalname}`))
.on('finish', Promise.resolve)
.on('error', Promise.reject)