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;
|
return typeof s === "string" ? encoder.encode(s) : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function encode_utf8(s: BinaryLike, buf: Uint8Array): number {
|
export function encode_utf8(s: BinaryLike, buf: Uint8Array, offset = 0) {
|
||||||
if (typeof s === "string") return encoder.encodeInto(s, buf).written;
|
if (typeof s === "string") {
|
||||||
else return buf.set(s), s.length;
|
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 {
|
export function from_hex(s: BinaryLike): Uint8Array {
|
||||||
|
Loading…
Reference in New Issue
Block a user