From ddbe9f4b366b7a15afc036b2ad735f0e5fc0a97e Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 6 Jul 2018 00:33:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20waiting=20for=20file?= =?UTF-8?q?=20to=20be=20written=20to=20disk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/funcs/saveResponse.ts | 8 ++++---- src/ssn/getPatch.ts | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cdn/funcs/saveResponse.ts b/src/cdn/funcs/saveResponse.ts index 896c80b..7765dcc 100644 --- a/src/cdn/funcs/saveResponse.ts +++ b/src/cdn/funcs/saveResponse.ts @@ -54,11 +54,11 @@ export default function saveResponse( return reject(`Expected length ${headerLength} but received ${totalLength}.`); } - //Return file reader + //wait until everything is written to disk, then return file name //TODO: need to automatically delete file once it is no longer used //TODO: need to provide methods to seek through file - return resolve(tempFileName); - //const stream = fs.createReadStream(tempFileName); - //return resolve(stream); + previousChunk.then(() => { + resolve(tempFileName); + }); }); } diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index df87e6f..a99f379 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -32,9 +32,6 @@ export default async function getPatch(product: Product, from: number, to: numbe //Then we need to wait for disks to finish download before we can extract individual files //TODO: we can optimize this to already extract some files as soon as their relevant parts are downloaded const diskFilenames = await Promise.all(diskFiles); - console.log('Waiting for everything to be written to disk...'); - await new Promise((resolve) => { setTimeout(resolve, 15000); }); - console.log('Done!'); //const dvArray = bufferArray.map((buffer) => new DataView(buffer)); //TODO: Verify that downloaded files match the hash in `solidpkg.pieces`