Skip to content

Commit 8bc7a27

Browse files
committed
fix: breaking change in arraybuffer utils
1 parent 749789e commit 8bc7a27

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/web/encode-text-arraybuffer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export function encodeText(input: string) {
22
return new TextEncoder().encode(input)
33
}
44

5-
export function decodeText(input: Iterable<number>) {
5+
export function decodeText(input: Iterable<number> | ArrayBuffer) {
6+
if (input instanceof ArrayBuffer) return new TextDecoder().decode(input)
67
return new TextDecoder().decode(Uint8Array.from(input))
78
}
89

@@ -15,9 +16,9 @@ export function decodeArrayBuffer(input: string) {
1516
return buffer.buffer
1617
}
1718

18-
export function encodeArrayBuffer(input: Iterable<number>) {
19+
export function encodeArrayBuffer(input: Iterable<number> | ArrayBuffer) {
1920
let encoded = ''
20-
for (const code of Uint8Array.from(input)) {
21+
for (const code of input instanceof ArrayBuffer ? new Uint8Array(input) : Uint8Array.from(input)) {
2122
encoded += String.fromCharCode(code)
2223
}
2324
return btoa(encoded)

0 commit comments

Comments
 (0)