@@ -7,8 +7,6 @@ import { NestedError } from "ts-nested-error";
77
88const pipeline = util . promisify ( stream . pipeline ) ;
99
10- class DownloadFileError extends NestedError { }
11-
1210/**
1311 * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`.
1412 * `onProgress` callback is called on recieveing each chunk of bytes
@@ -21,13 +19,13 @@ export async function downloadFile(
2119 destFilePermissions : number ,
2220 onProgress : ( readBytes : number , totalBytes : number ) => void
2321) : Promise < void > {
24- const res = await fetch ( url ) . catch ( DownloadFileError . rethrow ( "Failed at initial fetch" ) ) ;
22+ const res = await fetch ( url ) . catch ( NestedError . rethrow ( "Failed at initial fetch" ) ) ;
2523
2624 if ( ! res . ok ) {
2725 console . log ( "Error" , res . status , "while downloading file from" , url ) ;
2826 console . dir ( { body : await res . text ( ) , headers : res . headers } , { depth : 3 } ) ;
2927
30- throw new DownloadFileError ( `Got response ${ res . status } ` ) ;
28+ throw new NestedError ( `Got response ${ res . status } ` ) ;
3129 }
3230
3331 const totalBytes = Number ( res . headers . get ( 'content-length' ) ) ;
@@ -43,9 +41,12 @@ export async function downloadFile(
4341
4442 const destFileStream = fs . createWriteStream ( destFilePath , { mode : destFilePermissions } ) ;
4543
46- await pipeline ( res . body , destFileStream ) . catch ( DownloadFileError . rethrow ( "Piping file error" ) ) ;
44+ await pipeline ( res . body , destFileStream ) . catch ( NestedError . rethrow ( "Piping file error" ) ) ;
4745 return new Promise < void > ( resolve => {
48- destFileStream . on ( "close" , resolve ) ; // details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131
46+ destFileStream . on ( "close" , resolve ) ;
4947 destFileStream . destroy ( ) ;
48+
49+ // Details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131
50+ // Issue at nodejs repo: https://github.com/nodejs/node/issues/31776
5051 } ) ;
5152}
0 commit comments