shim more buffer methods, and fs methods

getting importer plugin to work,
This commit is contained in:
Nystik
2026-03-23 22:58:01 +01:00
parent 6dd62a15fa
commit a98afa46f5
10 changed files with 533 additions and 6 deletions

View File

@@ -197,5 +197,48 @@ export function createFsPromises(metadataCache, contentCache, transport) {
metadataCache.set(path, meta);
}
},
async open(path, flags) {
if (!metadataCache.has(path)) {
const err = new Error(
`ENOENT: no such file or directory, open '${path}'`,
);
err.code = "ENOENT";
throw err;
}
const data = await this.readFile(path);
const fileData =
typeof data === "string" ? new TextEncoder().encode(data) : data;
const fileStat = metadataCache.toStat(path) || {
size: fileData.length,
isFile: () => true,
isDirectory: () => false,
};
return {
async stat() {
return fileStat;
},
async read(buffer, offset, length, position) {
const available = Math.min(length, fileData.length - position);
if (available <= 0) {
return { bytesRead: 0, buffer };
}
const slice = fileData.subarray(position, position + available);
buffer.set(slice, offset);
return { bytesRead: available, buffer };
},
async close() {
// Nothing to clean up - data is in memory
},
};
},
};
}