From 86ba51731c3a99a6359ea1961e9cae6087475a58 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 5 Jul 2018 22:18:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20error=20message=20to=20get?= =?UTF-8?q?FileFromdisks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/streams/getFileFromDisks.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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);