Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on createReadStream(buffer) #18794

Closed
tobq opened this issue Feb 15, 2018 · 10 comments
Closed

Error on createReadStream(buffer) #18794

tobq opened this issue Feb 15, 2018 · 10 comments

Comments

@tobq
Copy link

tobq commented Feb 15, 2018

  • Version: 9.5
  • Platform: Windows 10 64 bit
  • Subsystem: fs
fs.createReadStream(buffer);

Error [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string without null bytes. Received type object

@BridgeAR
Copy link
Member

I can not reproduce this on Linux. Would you be so kind and show a stack trace?

@tobq
Copy link
Author

tobq commented Feb 15, 2018

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)

@apapirovski
Copy link
Member

@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.

@tobq
Copy link
Author

tobq commented Feb 15, 2018

Yes, I did some reading and realised it was expecting paths in buffer form, not data buffers.

@tobq tobq closed this as completed Feb 15, 2018
@falcon1996
Copy link

I am facing the same issue, please share how did you resolve it?

@wuyunjiang
Copy link

I am facing the same issue

@w3debugger
Copy link

w3debugger commented Sep 3, 2019

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)

@tobq
Copy link
Author

tobq commented Sep 3, 2019

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.

@AdamBD
Copy link

AdamBD commented Sep 30, 2020

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

@wangtaigong
Copy link

// There is a way to create a ReadStream from a data buffer in node.
import { Readable} from 'stream';
Readable.from(buffer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants