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. */