Add offset argument to encode_utf8
This commit is contained in:
parent
4c86c8b7f4
commit
328cb0c655
10
bytes.ts
10
bytes.ts
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user