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

Stream created from readable-stream module does not work #1503

Closed
2 tasks done
kanongil opened this issue Oct 17, 2020 · 2 comments
Closed
2 tasks done

Stream created from readable-stream module does not work #1503

kanongil opened this issue Oct 17, 2020 · 2 comments
Labels
enhancement This change will extend Got features

Comments

@kanongil
Copy link

Describe the bug

  • Node.js version: any
  • OS & version: n/a

Actual behavior

Rejected with error: RequestError: The `body` option must be a stream.Readable, string or Buffer

Expected behavior

Upload the stream data as request body.

The readable-stream module is a node official implementation of streams2+, with 50M weekly downloads. It is recommended to use to get a stable stream implementation across node releases, so I would expect it to work here.

Code to reproduce

const Got = require('got');
const { Readable } = require('readable-stream');

const stream = new Readable({
  _read() {
    this.push('ok');
    this.push(null);
  }
});

Got.post('http://google.com', {
  body: stream
}).catch(console.error);

Note, this is fixed with #1424, but there might be a more appropriate fix, like a duck-typed check for the _readableState property.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@sindresorhus
Copy link
Owner

I would recommend opening an issue on Node.js about adding a Stream.isStream() method, like Buffer.isBuffer().

For now, I guess we could just borrow the logic from https://github.com/sindresorhus/is-stream/blob/46239f19bafec11fd4c04fc09819fb7ca48b4f1f/index.js#L3-L6

I would prefer to see an enhancement request in the Node.js issue tracker before we add our own duck-typing/workaround though.

@szmarczak szmarczak added the enhancement This change will extend Got features label Oct 17, 2020
@szmarczak
Copy link
Collaborator

Is is-stream included in @sindresorhus/is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This change will extend Got features
Projects
None yet
Development

No branches or pull requests

3 participants