According to docs https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options
fs.createReadStream() can accept Buffer as first argument
my node code:
@jfriend00 has already provided a very clear explanation on this issue. If a Buffer object is passed as argument to fs.createReadStream(), it should indicate the file path, not file content. As @Littlee asked in comment, here is an example code:
var express = require('express');
var router = express.Router();
var fs = require('fs')
router.get('/test', function(req, res) {
var buf = Buffer.from('./test.html');
fs.createReadStream(buf).pipe(res);
});
Please note the Buffer buf
indicates a file path ("./test.html"
), not the file test.html
's content.