@warren-bank/browser-fetch-progress
v1.0.0
Published
A middleware function for use with the browser 'Fetch API' to provide download progress updates.
Downloads
5
Readme
fetchProgress
A middleware function for use with the browser Fetch API to provide download progress updates.
CDN
Usage
const buffer = await fetch(url)
.then(fetchProgress(event => console.log(`download is ${event.progress * 100} percent complete..`)))
.then(res => res.arrayBuffer())Examples
Notes
fetchProgressis a function- it accepts 1 input parameter
- an event handler function
- lets call it
progressHandler
- it accepts 1 input parameter
progressHandleris a function- it accepts 1 input parameter
- an Object
- lets call it
event- it has 1 attribute
- name:
progress - value: number within the inclusive range 0 to 1
- name:
- it has 1 attribute
- it returns a Promise that resolves to an instance of a class
- having the following public methods:
arrayBuffer()blob()bytes()json()text()
- having the following public properties:
headersokredirectedstatusstatusTexttypeurl
- these public methods and properties can be used as drop-in replacements for several of the methods and properties provided by the Response class, with the following caveats:
headersis a plain key/value Object, rather than an instance of the Headers class
- having the following public methods:
- it accepts 1 input parameter
Credits
- article: "Fetch: Download progress"
- article: "A horrifying 'globalThis' polyfill in universal JavaScript"
Legal
- copyright: Warren Bank
- license: GPL-2.0
