🚑 Fix reading of local file header
This commit is contained in:
parent
520f9c2e39
commit
4f0adf8931
2 changed files with 7 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
"name": "patcher",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "rm -rf dist && tsc && node dist/index.js",
|
||||
"start": "rm -rf dist && tsc",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -11,18 +11,18 @@ import streamSetMaxLength from './streams/streamSetMaxLength';
|
|||
* and must transparently span across multiple disks if necessary.
|
||||
*/
|
||||
export default function extractFileStream(file: ISsnFileEntry, inputStream: stream.Readable): stream.Readable {
|
||||
const headerBuffer: Buffer = inputStream.read(30);
|
||||
const localFileHeader = new DataView(headerBuffer.buffer);
|
||||
const localFileHeader: Buffer = inputStream.read(30);
|
||||
|
||||
//Local file header signature
|
||||
if (localFileHeader.getUint32(0, true) !== 0x04034B50) {
|
||||
throw new Error('Local file header had wrong magic');
|
||||
const magic = localFileHeader.readUInt32LE(0);
|
||||
if (magic !== 0x04034B50) {
|
||||
throw new Error(`Local file header had wrong magic; expected 0x04034B50 but got 0x${magic.toString(16).padStart(8, '0')}`);
|
||||
}
|
||||
//All fields in the local file header are copies of the central file header, so we can skip them.
|
||||
//FIXME: Maybe we should actually read these fields to verify that they are identical?
|
||||
//skip 22 bytes
|
||||
const localFilenameSize = localFileHeader.getUint16(26, true);
|
||||
const localExtraSize = localFileHeader.getUint16(28, true);
|
||||
const localFilenameSize = localFileHeader.readUInt16LE(26);
|
||||
const localExtraSize = localFileHeader.readUInt16LE(28);
|
||||
|
||||
//skip local file name and extra field
|
||||
inputStream.read(localFilenameSize + localExtraSize);
|
||||
|
|
Loading…
Reference in a new issue