From 79755fca926b968165fbb21ccfe416b9cc72e330 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Sat, 21 Oct 2023 13:33:25 -0400 Subject: [PATCH] Same improvements for Windows --- src/projector/otto/windows.ts | 45 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/projector/otto/windows.ts b/src/projector/otto/windows.ts index cb7e7e0..75145d8 100644 --- a/src/projector/otto/windows.ts +++ b/src/projector/otto/windows.ts @@ -129,26 +129,37 @@ export class ProjectorOttoWindows extends ProjectorOtto { * @param dest Output path. */ const extract = async (entry: Entry, dest: string) => { - let data: Uint8Array | null = null; - for (const patch of patches) { - if ( - entry.type === PathType.FILE && - patch.match(entry.volumePath) - ) { - // eslint-disable-next-line no-await-in-loop - data = data || (await entry.read()); - if (!data) { - throw new Error(`Failed to read: ${entry.volumePath}`); + if (entry.type === PathType.FILE) { + let data: Uint8Array | null = null; + for (const patch of patches) { + if (patch.match(entry.volumePath)) { + if (!data) { + // eslint-disable-next-line no-await-in-loop + const d = await entry.read(); + if (!d) { + throw new Error( + `Failed to read: ${entry.volumePath}` + ); + } + data = new Uint8Array( + d.buffer, + d.byteOffset, + d.byteLength + ); + } + // eslint-disable-next-line no-await-in-loop + data = await patch.modify(data); } - // eslint-disable-next-line no-await-in-loop - data = await patch.modify(data); } - } - if (data) { - await mkdir(dirname(dest), {recursive: true}); - await writeFile(dest, data); - return; + if (data) { + await mkdir(dirname(dest), {recursive: true}); + await writeFile(dest, data); + await entry.setAttributes(dest, null, { + ignoreTimes: true + }); + return; + } } await entry.extract(dest);