diff --git a/src/ssn/streams/getFileFromDisks.ts b/src/ssn/streams/getFileFromDisks.ts index b535bac..e3f6b5c 100644 --- a/src/ssn/streams/getFileFromDisks.ts +++ b/src/ssn/streams/getFileFromDisks.ts @@ -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);