diff --git a/src/ssn/extractFileStream.ts b/src/ssn/extractFileStream.ts index 678b4d4..2adf192 100644 --- a/src/ssn/extractFileStream.ts +++ b/src/ssn/extractFileStream.ts @@ -10,7 +10,7 @@ import streamSetMaxLength from './streams/streamSetMaxLength'; * The stream must already start at the .zip's local file header * and must transparently span across multiple disks if necessary. */ -export default function extractFileStream(file: ISsnFileEntry, inputStream: stream.Readable): stream.Readable { +export default function extractFileStream(file: ISsnFileEntry, inputStream: stream.Readable, skipDecompression: boolean = false): stream.Readable { let curStream = inputStream; curStream = streamSetMaxLength(curStream, file.compressedSize); @@ -21,13 +21,15 @@ export default function extractFileStream(file: ISsnFileEntry, inputStream: stre curStream = curStream.pipe(decryptTransform); } - /*//pipe into decompression - const decompressTransform = zlib.createInflateRaw(); - decompressTransform.on('error', (error) => { - //TODO: need to throw error sync, not async - throw new Error(`Error during decompression of "${file.name}": ${error.message}`); - }); - curStream = curStream.pipe(decompressTransform);*/ + if (skipDecompression) { + //pipe into decompression + const decompressTransform = zlib.createInflateRaw(); + decompressTransform.on('error', (error) => { + //TODO: need to throw error sync, not async + throw new Error(`Error during decompression of "${file.name}": ${error.message}`); + }); + curStream = curStream.pipe(decompressTransform); + } return curStream; } diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index e006503..5f2127a 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -40,7 +40,7 @@ export default async function getPatch(product: Product, from: number, to: numbe fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { try { const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); - const fileContents = extractFileStream(file, fileStream); + const fileContents = extractFileStream(file, fileStream, true); console.debug(await streamToArrayBuffer(fileContents)); //TODO: need to write to disk } catch (error) { @@ -52,7 +52,7 @@ export default async function getPatch(product: Product, from: number, to: numbe fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => { try { const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); - const fileContents = extractFileStream(file, fileStream); + const fileContents = extractFileStream(file, fileStream, true); console.debug(await streamToArrayBuffer(fileContents)); //TODO: need to apply diffing, then write to disk } catch (error) {