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:
var _ = require('lodash')
var faker = require('faker')
var http = require('http')
var fs = require('fs')
var xlsx = require('node-xlsx')
var gg = _.range(10).map((item) => {
return _.range(10).map((item) => {
return faker.name.findName()
})
})
http.createServer(function(req, res) {
var buf = xlsx.build([{
name: 'sheet1',
data: gg
}])
fs.createReadStream(buf, 'binary').pipe(res)
}).listen(9090)
but I get this error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: Path must be a string without null bytes
at nullCheck (fs.js:135:14)
at Object.fs.open (fs.js:627:8)
at ReadStream.open (fs.js:1951:6)
at new ReadStream (fs.js:1938:10)
at Object.fs.createReadStream (fs.js:1885:10)
at Server.<anonymous> (/Users/xpg/project/test/index.js:18:6)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:546:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
I just want to know that if I want to pass a Buffer as the path argument, what is the options I should provide, passing 'binary' doesn't work.
I try it with both Node 6.11.0 and Node 8.4.0