Add offset argument to encode_utf8

This commit is contained in:
luaneko 2025-01-09 19:48:28 +11:00
parent 4c86c8b7f4
commit 328cb0c655
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
2 changed files with 8 additions and 4 deletions

View File

@ -18,9 +18,13 @@ export function to_utf8(s: BinaryLike): Uint8Array {
return typeof s === "string" ? encoder.encode(s) : s;
}
export function encode_utf8(s: BinaryLike, buf: Uint8Array): number {
if (typeof s === "string") return encoder.encodeInto(s, buf).written;
else return buf.set(s), s.length;
export function encode_utf8(s: BinaryLike, buf: Uint8Array, offset = 0) {
if (typeof s === "string") {
if (offset !== 0) buf = buf.subarray(offset);
return encoder.encodeInto(s, buf).written;
} else {
return buf.set(s, offset), s.length;
}
}
export function from_hex(s: BinaryLike): Uint8Array {

View File

@ -1,5 +1,5 @@
{
"name": "@luaneko/lstd",
"version": "0.1.5",
"version": "0.1.6",
"exports": "./mod.ts"
}