@@ -58,12 +58,13 @@ export abstract class Emulator {
58
58
if ( err ) reject ( err ) ;
59
59
console . log ( `Created temporary directory at [${ dir } ].` ) ;
60
60
const filepath : string = path . resolve ( dir , this . binaryName ) ;
61
- const writer = fs . createWriteStream ( filepath ) ;
61
+ const buf : any [ ] = [ ] ;
62
62
console . log ( `Downloading emulator from [${ this . binaryUrl } ] ...` ) ;
63
63
// Map the DOM's fetch Reader to node's streaming file system
64
64
// operations. We will need to access class members `binaryPath` and `copyToCache` after the
65
65
// download completes. It's a compilation error to pass `this` into the named function
66
66
// `readChunk`, so the download operation is wrapped in a promise that we wait upon.
67
+ console . log ( process . memoryUsage ( ) . heapTotal ) ;
67
68
const downloadPromise = new Promise < void > (
68
69
( downloadComplete , downloadFailed ) => {
69
70
fetch ( this . binaryUrl )
@@ -75,9 +76,10 @@ export abstract class Emulator {
75
76
const reader = resp . body . getReader ( ) ;
76
77
reader . read ( ) . then ( function readChunk ( { done, value } ) : any {
77
78
if ( done ) {
79
+ console . log ( 'done download. buffer length:' , buf . length ) ;
78
80
downloadComplete ( ) ;
79
81
} else {
80
- writer . write ( value ) ;
82
+ buf . push ( ... value ) ;
81
83
return reader . read ( ) . then ( readChunk ) ;
82
84
}
83
85
} ) ;
@@ -96,6 +98,8 @@ export abstract class Emulator {
96
98
// Change emulator binary file permission to 'rwxr-xr-x'.
97
99
// The execute permission is required for it to be able to start
98
100
// with 'java -jar'.
101
+ fs . writeFileSync ( filepath , new Uint8Array ( buf ) ) ;
102
+
99
103
fs . chmod ( filepath , 0o755 , err => {
100
104
if ( err ) {
101
105
reject ( err ) ;
@@ -190,8 +194,8 @@ export abstract class Emulator {
190
194
}
191
195
192
196
if ( this . binaryPath ) {
193
- console . log ( `Deleting the emulator jar at ${ this . binaryPath } ` ) ;
194
- // fs.unlinkSync(this.binaryPath);
197
+ console . log ( `Deleting the emulator at ${ this . binaryPath } ` ) ;
198
+ fs . unlinkSync ( this . binaryPath ) ;
195
199
}
196
200
}
197
201
0 commit comments