🚧 Write compressed files to disk for debugging

This commit is contained in:
C-3PO 2018-07-08 22:49:56 +02:00
parent 32b0c39444
commit 864b6dc6f6
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
3 changed files with 12 additions and 6 deletions

View file

@ -2,10 +2,10 @@ import updateKeys from './lib/updateKeys';
export default function getDecryptionKeys(password: Uint8Array): [number, number, number] { export default function getDecryptionKeys(password: Uint8Array): [number, number, number] {
let [key0, key1, key2] = [0x12345678, 0x23456789, 0x34567890]; let [key0, key1, key2] = [0x12345678, 0x23456789, 0x34567890];
const passwordLength = password.length; const passwordLength = password.byteLength;
//read through password //read through password
for (let i = 0; i < passwordLength; i++) { for (let i = 0; i < passwordLength; i += 1) {
const curChar = password[i]; const curChar = password[i];
//Exit early if there's a zero byte in the password //Exit early if there's a zero byte in the password

View file

@ -1,5 +1,6 @@
//Similar to extractFile.ts, but instead of receiving and returning an ArrayBuffer, works with Node.js streams. //Similar to extractFile.ts, but instead of receiving and returning an ArrayBuffer, works with Node.js streams.
import * as fs from 'fs';
import * as stream from 'stream'; import * as stream from 'stream';
import * as zlib from 'zlib'; import * as zlib from 'zlib';
import { ISsnFileEntry } from '../interfaces/ISsnFileEntry'; import { ISsnFileEntry } from '../interfaces/ISsnFileEntry';
@ -21,6 +22,11 @@ export default async function extractFileAsStream(file: ISsnFileEntry, inputStre
await readBytesFromStream(curStream, 12); await readBytesFromStream(curStream, 12);
} }
if (skipDecompression) {
const fileStream = fs.createWriteStream(`/tmp/patcher/${file.name}`);
curStream.pipe(fileStream);
}
if (!skipDecompression) { if (!skipDecompression) {
//pipe into decompression //pipe into decompression
const decompressTransform = zlib.createInflateRaw(); const decompressTransform = zlib.createInflateRaw();

View file

@ -39,8 +39,8 @@ export default async function getPatch(product: Product, from: number, to: numbe
fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => {
try { try {
const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize }); const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize });
const fileContents = await extractFileAsStream(file, fileStream); const fileContents = await extractFileAsStream(file, fileStream, true);
console.debug(file.name, file.compressedSize, await streamToArrayBuffer(fileContents)); console.debug(file.name, file.compressedSize); //, await streamToArrayBuffer(fileContents));
//TODO: need to write to disk //TODO: need to write to disk
} catch (error) { } catch (error) {
console.error(`Could not extract file "${file.name}"`, error); console.error(`Could not extract file "${file.name}"`, error);
@ -51,8 +51,8 @@ export default async function getPatch(product: Product, from: number, to: numbe
fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => { fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => {
try { try {
const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize }); const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize });
const fileContents = await extractFileAsStream(file, fileStream); const fileContents = await extractFileAsStream(file, fileStream, true);
console.debug(file.name, file.compressedSize, await streamToArrayBuffer(fileContents)); console.debug(file.name, file.compressedSize); //, await streamToArrayBuffer(fileContents));
//TODO: need to apply diffing, then write to disk //TODO: need to apply diffing, then write to disk
} catch (error) { } catch (error) {
console.error(`Could not extract file "${file.name}"`, error); console.error(`Could not extract file "${file.name}"`, error);