🐛 Fix reading of local file header

This commit is contained in:
C-3PO 2018-07-05 23:42:42 +02:00
parent e84e5bd3d7
commit 74b312953d
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
3 changed files with 7 additions and 2 deletions

View file

@ -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;
}

View file

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

View file

@ -39,8 +39,13 @@ 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;
}