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

Make get-stream a devDependency #2365

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"cacheable-request": "^12.0.1",
"decompress-response": "^6.0.0",
"form-data-encoder": "^4.0.2",
"get-stream": "^8.0.1",
"http2-wrapper": "^2.2.1",
"lowercase-keys": "^3.0.0",
"p-cancelable": "^4.0.1",
Expand Down Expand Up @@ -86,6 +85,7 @@
"express": "^4.19.2",
"form-data": "^4.0.0",
"formdata-node": "^6.0.3",
"get-stream": "^9.0.1",
"nock": "^13.5.4",
"node-fetch": "^3.3.2",
"np": "^10.0.5",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret

[Click here][InstallSizeOfTheDependencies] to see the install size of the Got dependencies.

[InstallSizeOfTheDependencies]: https://packagephobia.com/result?p=@sindresorhus/is@6.3.1,@szmarczak/[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
[InstallSizeOfTheDependencies]: https://packagephobia.com/result?p=@sindresorhus/is@7.0.0,@szmarczak/[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]

## Maintainers

Expand Down
10 changes: 3 additions & 7 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import CacheableRequest, {
type CacheableOptions,
} from 'cacheable-request';
import decompressResponse from 'decompress-response';
import is from '@sindresorhus/is';
import {getStreamAsBuffer} from 'get-stream';
import is, {isBuffer} from '@sindresorhus/is';
import {FormDataEncoder, isFormData as isFormDataLike} from 'form-data-encoder';
import type ResponseLike from 'responselike';
import getBodySize from './utils/get-body-size.js';
Expand Down Expand Up @@ -877,11 +876,8 @@ export default class Request extends Duplex implements RequestEvents<Request> {

try {
// Errors are emitted via the `error` event
const rawBody = await getStreamAsBuffer(from);

// TODO: Switch to this:
// let rawBody = await from.toArray();
// rawBody = Buffer.concat(rawBody);
const fromArray = await from.toArray();
const rawBody = isBuffer(fromArray.at(0)) ? Buffer.concat(fromArray) : Buffer.from(fromArray.join(''));

// On retry Request is destroyed with no error, therefore the above will successfully resolve.
// So in order to check if this was really successfull, we need to check if it has been properly ended.
Expand Down