An error occurred when fs.createReadStream () put Buffer data into it.

clipboard.png
specific code such as the figure above
the whole code means to extract data from the database, cycle to see if the user has a base64-encoded avatar, and decode it into a buffer, and pass it to a readable stream. The reason why it is introduced into a readable stream here is that the Qiniuyun plug-in stipulates that it is a readable stream parameter.

Mar.23,2021

fs.createReadStream is not used to convert Buffer to ReadStream . Although it accepts a Buffer , there should still be a file path in Buffer . It just helps you decode the text.

the correct conversion from Buffer to ReadStream is as follows:

const stream = require('stream');
const bufferStream = new stream.PassThrough();
bufferStream.end(binaryData);
Menu