Skip to content

Commit bf93c4c

Browse files
committed
try again
1 parent 088b5ee commit bf93c4c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/emulator-testing/emulators/emulator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ export abstract class Emulator {
5858
if (err) reject(err);
5959
console.log(`Created temporary directory at [${dir}].`);
6060
const filepath: string = path.resolve(dir, this.binaryName);
61-
const writer = fs.createWriteStream(filepath);
61+
const buf: any[] = [];
6262
console.log(`Downloading emulator from [${this.binaryUrl}] ...`);
6363
// Map the DOM's fetch Reader to node's streaming file system
6464
// operations. We will need to access class members `binaryPath` and `copyToCache` after the
6565
// download completes. It's a compilation error to pass `this` into the named function
6666
// `readChunk`, so the download operation is wrapped in a promise that we wait upon.
67+
console.log(process.memoryUsage().heapTotal);
6768
const downloadPromise = new Promise<void>(
6869
(downloadComplete, downloadFailed) => {
6970
fetch(this.binaryUrl)
@@ -75,9 +76,10 @@ export abstract class Emulator {
7576
const reader = resp.body.getReader();
7677
reader.read().then(function readChunk({ done, value }): any {
7778
if (done) {
79+
console.log('done download. buffer length:', buf.length);
7880
downloadComplete();
7981
} else {
80-
writer.write(value);
82+
buf.push(...value);
8183
return reader.read().then(readChunk);
8284
}
8385
});
@@ -96,6 +98,8 @@ export abstract class Emulator {
9698
// Change emulator binary file permission to 'rwxr-xr-x'.
9799
// The execute permission is required for it to be able to start
98100
// with 'java -jar'.
101+
fs.writeFileSync(filepath, new Uint8Array(buf));
102+
99103
fs.chmod(filepath, 0o755, err => {
100104
if (err) {
101105
reject(err);
@@ -190,8 +194,8 @@ export abstract class Emulator {
190194
}
191195

192196
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);
195199
}
196200
}
197201

0 commit comments

Comments
 (0)