🐛 Add error message to getFileFromdisks

This commit is contained in:
C-3PO 2018-07-05 22:18:19 +02:00
parent 099fecce98
commit 86ba51731c
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -51,9 +51,14 @@ export default function getFileFromDisks(disks: string[], { diskStart, offset, s
const onData = (chunk: Buffer) => {
outputStream.write(chunk);
totalRead += chunk.length;
//TODO: need to end if we have read beyond the file
if (localFileHeaderLength !== 0 && totalRead >= localFileHeaderLength + storedSize) {
//TODO
}
};
const onEnd = () => {
curDiskIndex += 1;
//End if we are at end of file or end of disks
if (curDiskIndex >= disks.length || (localFileHeaderLength !== 0 && totalRead >= localFileHeaderLength + storedSize)) {
outputStream.end();
} else {
@ -61,11 +66,16 @@ export default function getFileFromDisks(disks: string[], { diskStart, offset, s
//set up new listeners for data and end
curDisk.on('data', onData);
curDisk.on('end', onEnd);
curDisk.on('error', onError);
}
};
const onError = (error: any) => {
console.error(error);
};
curDisk.on('data', onData);
curDisk.on('end', onEnd);
curDisk.on('error', onError);
//Read local file header
localFileHeaderLength = readLocalFileHeader(outputStream);