From 662c2d5f434ba81b56ace57b3252e328b70629d9 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 18:33:53 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20error=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/getPatch.ts | 24 ++++++++++++++++-------- src/ssn/streams/getFileFromDisks.ts | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 27f5233..e006503 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -38,18 +38,26 @@ export default async function getPatch(product: Product, from: number, to: numbe //Extract newly added files fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { - const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); - const fileContents = extractFileStream(file, fileStream); - console.debug(await streamToArrayBuffer(fileContents)); - //TODO: need to write to disk + try { + const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); + const fileContents = extractFileStream(file, fileStream); + console.debug(await streamToArrayBuffer(fileContents)); + //TODO: need to write to disk + } catch (error) { + console.error(`Could not extract file "${file.name}"`, error); + } }); //Extract changed files fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => { - const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); - const fileContents = extractFileStream(file, fileStream); - console.debug(await streamToArrayBuffer(fileContents)); - //TODO: need to apply diffing, then write to disk + try { + const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); + const fileContents = extractFileStream(file, fileStream); + console.debug(await streamToArrayBuffer(fileContents)); + //TODO: need to apply diffing, then write to disk + } catch (error) { + console.error(`Could not extract file "${file.name}"`, error); + } }); //Need to delete deleted files diff --git a/src/ssn/streams/getFileFromDisks.ts b/src/ssn/streams/getFileFromDisks.ts index 81cf273..220cf57 100644 --- a/src/ssn/streams/getFileFromDisks.ts +++ b/src/ssn/streams/getFileFromDisks.ts @@ -12,7 +12,7 @@ interface IGetFileFromDisksOptions { } function getStream(disks: string[], index: number, offset: number, length: number = Infinity) { - return fs.createReadStream(disks[index], { start: offset }); //, end: offset + length - 1 }); + return fs.createReadStream(disks[index], { start: offset }); } /** Takes a list of ReadableStreams (the disks), as well as the offset and length, and returns a stream for just one file. */