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

Progress events without breaking pub-sub #60

Merged
merged 13 commits into from
Nov 13, 2020
Prev Previous commit
Next Next commit
chore: apply suggestions from code review
  • Loading branch information
Gozala committed Nov 13, 2020
commit 6947fcd8eb713e05283b0017be8d9342238e2385
2 changes: 1 addition & 1 deletion src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const defaults = {
* @prop {function(any): any} [transform] - When iterating the response body, transform each chunk with this function.
* @prop {function(Response): Promise<void>} [handleError] - Handle errors
* @prop {function({total:number, loaded:number, lengthComputable:boolean}):void} [onUploadProgress] - Can be passed to track upload progress.
* Note that if this option in passed undelying request will be performed using `XMLHttpRequest` and response will not be streamed.
* Note that if this option in passed underlying request will be performed using `XMLHttpRequest` and response will not be streamed.
*/

class HTTP {
Expand Down
6 changes: 3 additions & 3 deletions src/http/fetch.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.Request = Request
exports.Headers = Headers

/**
* Takes fetch options and wraps request body to track uploda progress if
* Takes fetch options and wraps request body to track upload progress if
* `onUploadProgress` is supplied. Otherwise returns options as is.
* @param {FetchOptions} options
* @returns {FetchOptions}
Expand All @@ -56,14 +56,14 @@ const withUploadProgress = (options) => {

/**
* Takes request `body` and `onUploadProgress` handler and returns wrapped body
* that as consumed will report progress to suppled `onUploadProgress` handler.
* that as consumed will report progress to supplied `onUploadProgress` handler.
* @param {FetchOptions} init
* @param {function(LoadProgress):void} onUploadProgress
* @returns {Readable}
*/
const bodyWithUploadProgress = (init, onUploadProgress) => {
// This works around the fact that electron-fetch serializes `Uint8Array`s
// and `ArrayBuffer`'s to strings.
// and `ArrayBuffer`s to strings.
const content = normalizeBody(init.body)

// @ts-ignore - Response does not accept node `Readable` streams.
Expand Down
2 changes: 1 addition & 1 deletion test/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('http', function () {
onUploadProgress: (progress) => {
expect(progress).to.have.property('lengthComputable').to.be.a('boolean')
expect(progress).to.have.property('total', body.byteLength)
expect(progress).to.have.property('loaded').to.be.greaterThan(0)
expect(progress).to.have.property('loaded').that.is.greaterThan(0)
upload += 1
}
})
Expand Down