mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
shim more buffer methods, and fs methods
getting importer plugin to work,
This commit is contained in:
@@ -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());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user