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;