From 74b312953d1b93f0dfcc7a97fba40e577054bb63 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 5 Jul 2018 23:42:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20reading=20of=20local=20fil?= =?UTF-8?q?e=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/ISsnFileEntry.ts | 2 +- src/ssn/streams/getFileFromDisks.ts | 2 +- src/ssn/streams/readLocalFileHeader.ts | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ISsnFileEntry.ts b/src/interfaces/ISsnFileEntry.ts index 3765efb..a8eadb5 100644 --- a/src/interfaces/ISsnFileEntry.ts +++ b/src/interfaces/ISsnFileEntry.ts @@ -30,7 +30,7 @@ interface ISsnFileEntry { decryptionKeys: [number, number, number] | undefined; /** Number of the disk where the file is stored (0=.z01, 1=.z02 etc.) */ diskNumberStart: number; - /** Offset */ + /** Offset into the disk to where the local file header starts. */ offset: number; } diff --git a/src/ssn/streams/getFileFromDisks.ts b/src/ssn/streams/getFileFromDisks.ts index 6a949c6..1b578f4 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 }); + return fs.createReadStream(disks[index], { start: offset, end: offset + length - 1 }); } /** Takes a list of ReadableStreams (the disks), as well as the offset and length, and returns a stream for just one file. */ diff --git a/src/ssn/streams/readLocalFileHeader.ts b/src/ssn/streams/readLocalFileHeader.ts index 84230eb..b47530b 100644 --- a/src/ssn/streams/readLocalFileHeader.ts +++ b/src/ssn/streams/readLocalFileHeader.ts @@ -39,7 +39,12 @@ export default async function readLocalFileHeader(inputStream: stream.Readable): const additionalLength = localFilenameSize + localExtraSize; if (additionalLength > 0) { await waitReadableLength(inputStream, additionalLength); + const tmpChunk = inputStream.read(additionalLength); + if (tmpChunk === null) { + //need to wait until data is ready for reading + await waitReadableLength(inputStream, additionalLength); inputStream.read(additionalLength); + } } return 30 + additionalLength;