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
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ Created because [`request`](https://github.com/request/request) is bloated *(sev
21
21
-[Request cancelation](#aborting-the-request)
22
22
-[Follows redirects](#followredirect)
23
23
-[Retries on network failure](#retries)
24
+
-[Progress events](#onuploadprogress-progress)
24
25
-[Handles gzip/deflate](#decompress)
25
26
-[Timeout handling](#timeout)
26
27
-[Errors with metadata](#errors)
@@ -202,6 +203,36 @@ got.stream('github.com')
202
203
203
204
`redirect` event to get the response object of a redirect. The second argument is options for the next request to the redirect location.
204
205
206
+
##### .on('uploadProgress', progress)
207
+
##### .on('downloadProgress', progress)
208
+
209
+
Progress events for uploading (sending request) and downloading (receiving response). The `progress` argument is an object like:
210
+
211
+
```js
212
+
{
213
+
percent:0.1,
214
+
transferred:1024,
215
+
total:10240
216
+
}
217
+
```
218
+
219
+
If it's not possible to retrieve the body size (can happen when streaming), `total` will be `null`.
220
+
221
+
**Note**: Progress events can also be used with promises.
222
+
223
+
```js
224
+
got('todomvc.com')
225
+
.on('downloadProgress', progress=> {
226
+
// Report download progress
227
+
})
228
+
.on('uploadProgress', progress=> {
229
+
// Report upload progress
230
+
})
231
+
.then(response=> {
232
+
// Done
233
+
});
234
+
```
235
+
205
236
##### .on('error', error, body, response)
206
237
207
238
`error` event emitted in case of protocol error (like `ENOTFOUND` etc.) or status error (4xx or 5xx). The second argument is the body of the server response in case of status error. The third argument is response object.
0 commit comments