mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-06 03:50:18 +02:00
refactor: code cleanup
This commit is contained in:
parent
c440e83828
commit
721b6c0da6
68 changed files with 1161 additions and 1036 deletions
|
@ -80,15 +80,15 @@ interface GlobalExtension {
|
|||
|
||||
const { TextEncoder, TextDecoder } = globalThis as unknown as GlobalExtension;
|
||||
|
||||
const Utf8Encoder = new TextEncoder();
|
||||
const Utf8Decoder = new TextDecoder();
|
||||
const SharedEncoder = new TextEncoder();
|
||||
const SharedDecoder = new TextDecoder();
|
||||
|
||||
export function encodeUtf8(input: string): Uint8Array {
|
||||
return Utf8Encoder.encode(input);
|
||||
return SharedEncoder.encode(input);
|
||||
}
|
||||
|
||||
export function decodeUtf8(buffer: ArrayBufferView | ArrayBuffer): string {
|
||||
// `TextDecoder` has internal states in stream mode,
|
||||
// but we don't use stream mode here, so it's safe to reuse the instance
|
||||
return Utf8Decoder.decode(buffer);
|
||||
// but this method is not for stream mode, so the instance can be reused
|
||||
return SharedDecoder.decode(buffer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue