platform.browser.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { decodePartAddition as decodePart } from './platform.native.js'
  2. export { isLE, encodeCharcodesPure as encodeCharcodes } from './platform.native.js'
  3. export const nativeBuffer = null
  4. export const isHermes = false
  5. export const isDeno = false
  6. export const nativeEncoder = /* @__PURE__ */ (() => new TextEncoder())()
  7. export const nativeDecoder = /* @__PURE__ */ (() => new TextDecoder('utf-8', { ignoreBOM: true }))()
  8. export const nativeDecoderLatin1 = /* @__PURE__ */ (() =>
  9. new TextDecoder('latin1', { ignoreBOM: true }))()
  10. export function decode2string(arr, start, end, m) {
  11. if (end - start > 30_000) {
  12. // Limit concatenation to avoid excessive GC
  13. // Thresholds checked on Hermes for toHex
  14. const concat = []
  15. for (let i = start; i < end; ) {
  16. const step = i + 500
  17. const iNext = step > end ? end : step
  18. concat.push(decodePart(arr, i, iNext, m))
  19. i = iNext
  20. }
  21. const res = concat.join('')
  22. concat.length = 0
  23. return res
  24. }
  25. return decodePart(arr, start, end, m)
  26. }