From 45d487f4fc449932aac64131bcff59ec1682ce7c Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 27 Sep 2026 20:46:51 +0200 Subject: [PATCH] vscode: make sure files are passed as bytes --- extension/src/buildcore.ts | 3 ++- extension/test/buildcore.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extension/src/buildcore.ts b/extension/src/buildcore.ts index 5ac19842..501334ef 100644 --- a/extension/src/buildcore.ts +++ b/extension/src/buildcore.ts @@ -155,7 +155,8 @@ export class ProjectFileProvider implements FileProvider { } } if (data == null) return null; - return isProbablyBinary(relpath) ? data : new TextDecoder().decode(data); + // the extension list is only a hint; the bytes decide (an .hgr, say) + return isProbablyBinary(relpath, data) ? data : new TextDecoder().decode(data); } } diff --git a/extension/test/buildcore.test.ts b/extension/test/buildcore.test.ts index c504edba..f44dd203 100644 --- a/extension/test/buildcore.test.ts +++ b/extension/test/buildcore.test.ts @@ -26,6 +26,20 @@ describe('extension buildcore', function () { assert.ok(!isSourceFile('settings.json')); }); + // Files the project reads at build time must survive as bytes when they + // aren't text, even if their extension isn't on the binary list (.hgr). + it('keeps binary files binary and decodes text', async function () { + var raw: { [path: string]: Uint8Array } = { + 'logo.hgr': new Uint8Array([0x25, 0x55, 0xaa, 0xd5]), // invalid UTF-8 + 'main.s': new TextEncoder().encode('\t.byte 1\n'), + }; + var files = new ProjectFileProvider(async rel => raw[rel] ?? null, ROOT, 'apple2'); + var hgr = await files.readFile('logo.hgr') as Uint8Array; + assert.ok(hgr instanceof Uint8Array); + assert.deepEqual(Array.from(hgr), [0x25, 0x55, 0xaa, 0xd5]); + assert.equal(await files.readFile('main.s'), '\t.byte 1\n'); + }); + it('builds a C file with a local header and a preset header', async function () { var files = project({ 'main.c': '#include "neslib.h"\n#include "util.h"\nvoid main(void) { ppu_on_all(); while (1) { x = 1; } }\n',