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

@@ -24,6 +24,18 @@ function installBuffer() {
return new Uint8Array(data);
},
alloc: function (size, fill, encoding) {
const buf = new Uint8Array(size);
if (fill !== undefined) {
buf.fill(typeof fill === "string" ? fill.charCodeAt(0) : fill);
}
return buf;
},
allocUnsafe: function (size) {
return new Uint8Array(size);
},
concat: function (arrays) {
const total = arrays.reduce((sum, a) => sum + a.length, 0);
const result = new Uint8Array(total);
@@ -39,6 +51,20 @@ function installBuffer() {
isBuffer: function (obj) {
return obj instanceof Uint8Array;
},
byteLength: function (str, encoding) {
return new TextEncoder().encode(str).length;
},
isEncoding: function (encoding) {
return [
"utf8",
"utf-8",
"ascii",
"binary",
"base64",
"hex",
"latin1",
].includes((encoding || "").toLowerCase());
},
};
}