You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: readme.md
+13-7
Original file line number
Diff line number
Diff line change
@@ -248,17 +248,21 @@ Default: `'default'`
248
248
249
249
Parsing method used to retrieve the body from the response.
250
250
251
-
-`'default'` - if `options.encoding` is `null`, the body will be a Buffer. Otherwise it will be a string unless it's overwritten in a `afterResponse` hook,
252
-
-`'text'` - will always give a string, no matter what's the `options.encoding` or if the body is a custom object,
253
-
-`'json'` - will always give an object, unless it's invalid JSON - then it will throw.
254
-
-`'buffer'` - will always give a Buffer, no matter what's the`options.encoding`. It will throw if the body is a custom object.
251
+
-`'default'` - Will give a string unless the body is overwritten in a `afterResponse` hook or if `options.decompress` is set to false - Will give a Buffer if the response is compresssed.
252
+
-`'text'` - Will give a string no matter what.
253
+
-`'json'` - Will give an object, unless the body is invalid JSON, then it will throw.
254
+
-`'buffer'` - Will give a Buffer, ignoring`options.encoding`. It will throw if the body is a custom object.
255
255
256
-
The promise has `.json()` and `.buffer()` and `.text()`functions which set this option automatically.
256
+
The promise has `.json()` and `.buffer()` and `.text()`methods which set this option automatically.
257
257
258
258
Example:
259
259
260
260
```js
261
+
// This
261
262
constbody=awaitgot(url).json();
263
+
264
+
// is the same as this
265
+
constbody=awaitgot(url, {responseType:'json'});
262
266
```
263
267
264
268
###### resolveBodyOnly
@@ -297,10 +301,12 @@ Ignore invalid cookies instead of throwing an error. Only useful when the `cooki
297
301
298
302
###### encoding
299
303
300
-
Type: `string | null`<br>
304
+
Type: `string`<br>
301
305
Default: `'utf8'`
302
306
303
-
[Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on `setEncoding` of the response data. If `null`, the body is returned as a [`Buffer`](https://nodejs.org/api/buffer.html) (binary data).
307
+
[Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on `setEncoding` of the response data.
308
+
309
+
To get a [`Buffer`](https://nodejs.org/api/buffer.html), you need to set [`responseType`](#responseType) to `buffer` instead.
0 commit comments