🎨 Improve waiting for file to be written to disk

This commit is contained in:
C-3PO 2018-07-06 00:33:36 +02:00
parent 253e22b9d6
commit ddbe9f4b36
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
2 changed files with 4 additions and 7 deletions

View file

@ -54,11 +54,11 @@ export default function saveResponse(
return reject(`Expected length ${headerLength} but received ${totalLength}.`); 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 automatically delete file once it is no longer used
//TODO: need to provide methods to seek through file //TODO: need to provide methods to seek through file
return resolve(tempFileName); previousChunk.then(() => {
//const stream = fs.createReadStream(tempFileName); resolve(tempFileName);
//return resolve(stream); });
}); });
} }

View file

@ -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 //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 //TODO: we can optimize this to already extract some files as soon as their relevant parts are downloaded
const diskFilenames = await Promise.all(diskFiles); 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)); //const dvArray = bufferArray.map((buffer) => new DataView(buffer));
//TODO: Verify that downloaded files match the hash in `solidpkg.pieces` //TODO: Verify that downloaded files match the hash in `solidpkg.pieces`