fs.createReadStream(buffer);
Error [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string without null bytes. Received type object
I can not reproduce this on Linux. Would you be so kind and show a stack trace?
console.log(buffer);
fs.createReadStream(buffer);
<Buffer 49 44 33 03 00 00 00 00 03 35 54 49 54 32 00 00 00 0f 00 00 00 4c 6f 76 65 20 4d 65 20 41 67 61 69 6e 00 54 50 45 31 00 00 00 0f 00 00 00 50 41 52 54 ... >
events.js:137
throw er; // Unhandled 'error' event
^
Error [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string without null bytes. Received type object
at nullCheck (fs.js:173:16)
at Object.fs.open (fs.js:648:8)
at ReadStream.open (fs.js:2057:6)
at new ReadStream (fs.js:2044:10)
at Object.fs.createReadStream (fs.js:1986:10)
at ***myfile***
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
@tobq The buffer in this case refers to a path string that's encoded as a buffer. It doesn't seem that the buffer you have is a path given all the null bytes.
Yes, I did some reading and realised it was expecting paths in buffer form, not data buffers.
I am facing the same issue, please share how did you resolve it?
I am facing the same issue
const data = require('./1.json');
const stream = fs.createReadStream(data);
relevant?
internal/fs/utils.js:453
throw err;
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object
at Object.open (fs.js:408:3)
at ReadStream.open (internal/fs/streams.js:110:12)
at new ReadStream (internal/fs/streams.js:99:10)
at Object.createReadStream (fs.js:1732:10)
at testing (/Users/w3debugger/Work/json-splitter/index.js:56:21)
at Object.<anonymous> (/Users/w3debugger/Work/json-splitter/index.js:78:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
As I explained, the API is expecting a path.
The buffer argument is simply the path string converted to a (string) buffer. Both accepted arguments are a path to the file, in different forms: String or Buffer.
It's misleading in that it isn't creating a readable-stream from a data-buffer.
is there a way to create a ReadStream from a data buffer in node? I too was mislead by this looking to create a stream from a data buffer
Most helpful comment
Yes, I did some reading and realised it was expecting paths in buffer form, not data buffers.