Skip to content

Commit

Permalink
More debug logs and log level fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lafkpages committed Oct 27, 2023
1 parent f685132 commit c6e7ab1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ export class Asar extends DirectoryEntry {

if (asarBytes) {
// Read header size
debug(1, "[new Asar] Reading header size");
debug(2, "[new Asar] Reading header size");
const headerSize = createFromBuffer(asarBytes.subarray(0, 16))
.createIterator()
.readUInt32();
debug(1, "[new Asar] Header size:", headerSize);
debug(2, "[new Asar] Header size:", headerSize);

// Read header
// We start at 16 because 0-8 are the Pickle object containing
// the header size, and 9-15 are the header size itself
debug(1, "[new Asar] Reading header");
debug(2, "[new Asar] Reading header");
const rawHeader = asarBytes.subarray(16, headerSize + 16).toString();
const header = JSON.parse(rawHeader) as unknown;

Expand Down Expand Up @@ -125,7 +125,7 @@ export class Asar extends DirectoryEntry {

if (!opts.noFileData) {
// Read all files
debug(1, "[new Asar] Reading files");
debug(2, "[new Asar] Reading files");
for (const [, filePath, fileEntry] of this.walkFiles(false)) {
// We can assume that fileEntry is a FileEntry,
// because we specified walkFiles(false)
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Asar extends DirectoryEntry {

const asar = new Asar(undefined, opts);

debug(1, "[Asar.fromDirectory] Walking directory");
debug(2, "[Asar.fromDirectory] Walking directory");
for await (const [filePath] of walk(inputDir)) {
const fileData = await readFile(joinPaths(inputDir, filePath));

Expand Down Expand Up @@ -394,15 +394,16 @@ export class Asar extends DirectoryEntry {
}
}

debug(2, "[Asar.getData] Creating header data");
const headerDataStr = JSON.stringify(headerData);
const headerPickle = createEmpty();
if (!headerPickle.writeString(headerDataStr)) {
throw new Error("[Asar.getData] Failed to write header data to Pickle");
}
const headerDataBuf = headerPickle.toBuffer();

debug(2, "[Asar.getData] Header size:", headerDataBuf.length);

debug(2, "[Asar.getData] Creating header size data");
debug(3, "[Asar.getData] Header size:", headerDataBuf.length);
const headerSizePickle = createEmpty();
if (!headerSizePickle.writeUInt32(headerDataBuf.length)) {
throw new Error("[Asar.getData] Failed to write header size to Pickle");
Expand All @@ -411,6 +412,7 @@ export class Asar extends DirectoryEntry {

const bufs = [headerSizeDataBuf, headerDataBuf];

debug(2, "[Asar.getData] Creating file data");
for (const [, filePath, fileEntry] of entries) {
if (BaseEntry.isFile(fileEntry)) {
const fileDataBuf = this.readFile(filePath);
Expand All @@ -428,6 +430,7 @@ export class Asar extends DirectoryEntry {
}
}

debug(2, "[Asar.getData] Creating final buffer");
const buf = new Uint8Array(bufs.reduce((acc, buf) => acc + buf.length, 0));

let offset = 0;
Expand Down Expand Up @@ -472,7 +475,7 @@ export class Asar extends DirectoryEntry {

const asarData = this.getData(opts);

debug(1, "[Asar.saveData] Writing to file");
debug(2, "[Asar.saveData] Writing to file");
await writeFile(asarPath, asarData.bytes);
}
}

0 comments on commit c6e7ab1

Please sign in to comment.