99} from './types' ;
1010
1111/**
12- *
13- * @param param0
14- * @returns
12+ * Resolver function to handle the download progress.
13+ * @param { ResolverProps } props
14+ * @returns { Response }
1515 */
1616export const resolver =
1717 ( {
@@ -20,73 +20,73 @@ export const resolver =
2020 setPercentageCallback,
2121 setErrorCallback,
2222 } : ResolverProps ) =>
23- ( response : Response ) : Response => {
24- if ( ! response . ok ) {
25- throw Error ( `${ response . status } ${ response . type } ${ response . statusText } ` ) ;
26- }
23+ ( response : Response ) : Response => {
24+ if ( ! response . ok ) {
25+ throw Error ( `${ response . status } ${ response . type } ${ response . statusText } ` ) ;
26+ }
2727
28- if ( ! response . body ) {
29- throw Error ( 'ReadableStream not yet supported in this browser.' ) ;
30- }
28+ if ( ! response . body ) {
29+ throw Error ( 'ReadableStream not yet supported in this browser.' ) ;
30+ }
3131
32- const responseBody = response . body ;
32+ const responseBody = response . body ;
3333
34- const contentEncoding = response . headers . get ( 'content-encoding' ) ;
35- const contentLength = response . headers . get (
36- contentEncoding ? 'x-file-size' : 'content-length'
37- ) ;
34+ const contentEncoding = response . headers . get ( 'content-encoding' ) ;
35+ const contentLength = response . headers . get (
36+ contentEncoding ? 'x-file-size' : 'content-length'
37+ ) ;
3838
39- const total = parseInt ( contentLength || '0' , 10 ) ;
39+ const total = parseInt ( contentLength || '0' , 10 ) ;
4040
41- setSize ( ( ) => total ) ;
41+ setSize ( ( ) => total ) ;
4242
43- let loaded = 0 ;
43+ let loaded = 0 ;
4444
45- const stream = new ReadableStream < Uint8Array > ( {
46- start ( controller ) {
47- setControllerCallback ( controller ) ;
45+ const stream = new ReadableStream < Uint8Array > ( {
46+ start ( controller ) {
47+ setControllerCallback ( controller ) ;
4848
49- const reader = responseBody . getReader ( ) ;
49+ const reader = responseBody . getReader ( ) ;
5050
51- async function read ( ) : Promise < void > {
52- return reader
53- . read ( )
54- . then ( ( { done, value } ) => {
55- if ( done ) {
56- return controller . close ( ) ;
57- }
51+ async function read ( ) : Promise < void > {
52+ return reader
53+ . read ( )
54+ . then ( ( { done, value } ) => {
55+ if ( done ) {
56+ return controller . close ( ) ;
57+ }
5858
59- loaded += value ?. byteLength || 0 ;
59+ loaded += value ?. byteLength || 0 ;
6060
61- if ( value ) {
62- controller . enqueue ( value ) ;
63- }
61+ if ( value ) {
62+ controller . enqueue ( value ) ;
63+ }
6464
65- setPercentageCallback ( { loaded, total } ) ;
65+ setPercentageCallback ( { loaded, total } ) ;
6666
67- return read ( ) ;
68- } )
69- . catch ( ( error : Error ) => {
70- setErrorCallback ( error ) ;
71- reader . cancel ( 'Cancelled' ) ;
67+ return read ( ) ;
68+ } )
69+ . catch ( ( error : Error ) => {
70+ setErrorCallback ( error ) ;
71+ reader . cancel ( 'Cancelled' ) ;
7272
73- return controller . error ( error ) ;
74- } ) ;
75- }
73+ return controller . error ( error ) ;
74+ } ) ;
75+ }
7676
77- return read ( ) ;
78- } ,
79- } ) ;
77+ return read ( ) ;
78+ } ,
79+ } ) ;
8080
81- return new Response ( stream ) ;
82- } ;
81+ return new Response ( stream ) ;
82+ } ;
8383
8484/**
85- *
86- * @param {Blob } data
87- * @param {string } filename
88- * @param {string } mime
89- * @returns
85+ * jsDownload function to handle the download process.
86+ * @param {Blob } data
87+ * @param {string } filename
88+ * @param {string } mime
89+ * @returns { boolean | NodeJS.Timeout }
9090 */
9191export const jsDownload = (
9292 data : Blob ,
@@ -131,9 +131,9 @@ export const jsDownload = (
131131} ;
132132
133133/**
134- * Initialise a new instance of downloader .
135- * @param {UseDownloaderOptions } options
136- * @returns UseDownloader
134+ * useDownloader hook to handle the download process .
135+ * @param {UseDownloaderOptions } options
136+ * @returns { UseDownloader }
137137 */
138138export default function useDownloader (
139139 options : UseDownloaderOptions = { }
0 commit comments