|
1 | | -export const TEXT_ENCODING_AVAILABLE = |
| 1 | +const TEXT_ENCODING_AVAILABLE = |
2 | 2 | typeof process !== "undefined" && |
3 | 3 | process.env.TEXT_ENCODING !== "never" && |
4 | 4 | typeof TextEncoder !== "undefined" && |
5 | 5 | typeof TextDecoder !== "undefined"; |
6 | 6 |
|
| 7 | +const STR_SIZE_MAX = 0xffff_ffff; // uint32_max |
| 8 | + |
7 | 9 | export function utf8Count(str: string): number { |
8 | 10 | const strLength = str.length; |
9 | 11 |
|
@@ -88,7 +90,11 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb |
88 | 90 | } |
89 | 91 |
|
90 | 92 | const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined; |
91 | | -export const TEXT_ENCODER_THRESHOLD = typeof process !== "undefined" && process.env.TEXT_ENCODING !== "force" ? 200 : 0; |
| 93 | +export const TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE |
| 94 | + ? STR_SIZE_MAX |
| 95 | + : typeof process !== "undefined" && process.env.TEXT_ENCODING !== "force" |
| 96 | + ? 200 |
| 97 | + : 0; |
92 | 98 |
|
93 | 99 | function utf8EncodeTEencode(str: string, output: Uint8Array, outputOffset: number): void { |
94 | 100 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
@@ -154,7 +160,11 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength: |
154 | 160 | } |
155 | 161 |
|
156 | 162 | const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null; |
157 | | -export const TEXT_DECODER_THRESHOLD = typeof process !== "undefined" && process.env.TEXT_DECODER !== "force" ? 200 : 0; |
| 163 | +export const TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE |
| 164 | + ? STR_SIZE_MAX |
| 165 | + : typeof process !== "undefined" && process.env.TEXT_DECODER !== "force" |
| 166 | + ? 200 |
| 167 | + : 0; |
158 | 168 |
|
159 | 169 | export function utf8DecodeTD(bytes: Uint8Array, inputOffset: number, byteLength: number): string { |
160 | 170 | const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength); |
|
0 commit comments