@@ -65,9 +65,13 @@ export class DownloadTask {
6565 0 ,
6666 params . targetFile . lastIndexOf ( '/' ) ,
6767 ) ;
68- await fileIo . mkdir ( targetDir ) ;
68+ const exists = fileIo . accessSync ( targetDir ) ;
69+ if ( ! exists ) {
70+ await fileIo . mkdir ( targetDir ) ;
71+ }
6972 }
7073 } catch ( error ) {
74+ throw error ;
7175 }
7276
7377 const response = await httpRequest . request ( params . url , {
@@ -78,12 +82,11 @@ export class DownloadTask {
7882 'Content-Type' : 'application/octet-stream' ,
7983 } ,
8084 } ) ;
81-
8285 if ( response . responseCode > 299 ) {
8386 throw new Error ( `Server error: ${ response . responseCode } ` ) ;
8487 }
8588
86- const contentLength = parseInt ( response . header [ 'Content-Length ' ] || '0' ) ;
89+ const contentLength = parseInt ( response . header [ 'content-length ' ] || '0' ) ;
8790 const writer = await fileIo . open (
8891 params . targetFile ,
8992 fileIo . OpenMode . CREATE | fileIo . OpenMode . READ_WRITE ,
@@ -102,8 +105,12 @@ export class DownloadTask {
102105 this . onProgressUpdate ( received , contentLength ) ;
103106 }
104107 await fileIo . close ( writer ) ;
105- const stat = await fileIo . stat ( params . targetFile ) ;
106- const fileSize = stat . size ;
108+ const stats = await fileIo . stat ( params . targetFile ) ;
109+ const fileSize = stats . size ;
110+ if ( fileSize !== contentLength ) {
111+ throw new Error ( `Download incomplete: expected ${ contentLength } bytes but got ${ stats . size } bytes` ) ;
112+ }
113+
107114 } catch ( error ) {
108115 console . error ( 'Download failed:' , error ) ;
109116 throw error ;
@@ -113,7 +120,7 @@ export class DownloadTask {
113120 }
114121
115122 private onProgressUpdate ( received : number , total : number ) : void {
116- this . eventHub . emit ( 'downloadProgress ' , {
123+ this . eventHub . emit ( 'RCTPushyDownloadProgress ' , {
117124 received,
118125 total,
119126 hash : this . hash ,
@@ -288,7 +295,7 @@ export class DownloadTask {
288295 }
289296 }
290297
291- if ( entry . filename !== '.DS_Store' ) {
298+ if ( fn !== '.DS_Store' ) {
292299 await zip . decompressFile ( entry . filename , params . unzipDirectory ) ;
293300 }
294301 }
@@ -491,4 +498,4 @@ export class DownloadTask {
491498 params . listener ?. onDownloadFailed ( error ) ;
492499 }
493500 }
494- }
501+ }
0 commit comments