2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../../core/lib.deno_core.d.ts" />
|
2021-07-06 08:38:12 -04:00
|
|
|
/// <reference path="../../core/internal.d.ts" />
|
2021-06-05 17:10:07 -04:00
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
2021-06-05 21:23:16 -04:00
|
|
|
/// <reference path="../fetch/lib.deno_fetch.d.ts" />
|
2021-06-05 17:10:07 -04:00
|
|
|
/// <reference path="../web/internal.d.ts" />
|
|
|
|
/// <reference path="../web/lib.deno_web.d.ts" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
|
2021-02-04 17:18:32 -05:00
|
|
|
"use strict";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
((window) => {
|
|
|
|
const core = Deno.core;
|
2022-08-11 09:56:56 -04:00
|
|
|
const ops = core.ops;
|
2021-06-05 17:10:07 -04:00
|
|
|
const webidl = window.__bootstrap.webidl;
|
2021-07-06 08:38:12 -04:00
|
|
|
const {
|
|
|
|
ArrayBufferIsView,
|
2022-02-01 12:06:11 -05:00
|
|
|
ObjectPrototypeIsPrototypeOf,
|
2021-07-06 08:38:12 -04:00
|
|
|
PromiseReject,
|
|
|
|
PromiseResolve,
|
|
|
|
StringPrototypeCharCodeAt,
|
|
|
|
StringPrototypeSlice,
|
|
|
|
TypedArrayPrototypeSubarray,
|
|
|
|
TypedArrayPrototypeSlice,
|
|
|
|
Uint8Array,
|
2022-09-17 07:18:15 -04:00
|
|
|
Uint32Array,
|
2021-07-06 08:38:12 -04:00
|
|
|
} = window.__bootstrap.primordials;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
class TextDecoder {
|
|
|
|
/** @type {string} */
|
|
|
|
#encoding;
|
|
|
|
/** @type {boolean} */
|
|
|
|
#fatal;
|
|
|
|
/** @type {boolean} */
|
|
|
|
#ignoreBOM;
|
|
|
|
|
|
|
|
/** @type {number | null} */
|
|
|
|
#rid = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} label
|
|
|
|
* @param {TextDecoderOptions} options
|
|
|
|
*/
|
|
|
|
constructor(label = "utf-8", options = {}) {
|
|
|
|
const prefix = "Failed to construct 'TextDecoder'";
|
|
|
|
label = webidl.converters.DOMString(label, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
options = webidl.converters.TextDecoderOptions(options, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
2022-08-11 09:56:56 -04:00
|
|
|
const encoding = ops.op_encoding_normalize_label(label);
|
2021-06-05 17:10:07 -04:00
|
|
|
this.#encoding = encoding;
|
|
|
|
this.#fatal = options.fatal;
|
|
|
|
this.#ignoreBOM = options.ignoreBOM;
|
|
|
|
this[webidl.brand] = webidl.brand;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/** @returns {string} */
|
|
|
|
get encoding() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
return this.#encoding;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/** @returns {boolean} */
|
|
|
|
get fatal() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
return this.#fatal;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/** @returns {boolean} */
|
|
|
|
get ignoreBOM() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
return this.#ignoreBOM;
|
2021-01-19 15:58:57 -05:00
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/**
|
|
|
|
* @param {BufferSource} [input]
|
|
|
|
* @param {TextDecodeOptions} options
|
|
|
|
*/
|
|
|
|
decode(input = new Uint8Array(), options = {}) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
const prefix = "Failed to execute 'decode' on 'TextDecoder'";
|
|
|
|
if (input !== undefined) {
|
|
|
|
input = webidl.converters.BufferSource(input, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
allowShared: true,
|
|
|
|
});
|
2021-01-19 15:58:57 -05:00
|
|
|
}
|
2021-06-05 17:10:07 -04:00
|
|
|
options = webidl.converters.TextDecodeOptions(options, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
2021-01-24 14:08:01 -05:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
try {
|
2021-10-28 17:17:27 -04:00
|
|
|
try {
|
|
|
|
if (ArrayBufferIsView(input)) {
|
|
|
|
input = new Uint8Array(
|
|
|
|
input.buffer,
|
|
|
|
input.byteOffset,
|
|
|
|
input.byteLength,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
input = new Uint8Array(input);
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// If the buffer is detached, just create a new empty Uint8Array.
|
|
|
|
input = new Uint8Array();
|
2021-01-24 14:08:01 -05:00
|
|
|
}
|
2022-02-01 12:06:11 -05:00
|
|
|
if (
|
|
|
|
ObjectPrototypeIsPrototypeOf(
|
|
|
|
SharedArrayBuffer.prototype,
|
|
|
|
input.buffer,
|
|
|
|
)
|
|
|
|
) {
|
2021-10-28 16:32:58 -04:00
|
|
|
// We clone the data into a non-shared ArrayBuffer so we can pass it
|
|
|
|
// to Rust.
|
|
|
|
// `input` is now a Uint8Array, and calling the TypedArray constructor
|
|
|
|
// with a TypedArray argument copies the data.
|
|
|
|
input = new Uint8Array(input);
|
|
|
|
}
|
2022-05-17 09:52:48 -04:00
|
|
|
|
|
|
|
if (!options.stream && this.#rid === null) {
|
2022-09-01 06:51:13 -04:00
|
|
|
return ops.op_encoding_decode_single(
|
|
|
|
input,
|
|
|
|
this.#encoding,
|
|
|
|
this.#fatal,
|
|
|
|
this.#ignoreBOM,
|
|
|
|
);
|
2022-05-17 09:52:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.#rid === null) {
|
2022-09-01 06:51:13 -04:00
|
|
|
this.#rid = ops.op_encoding_new_decoder(
|
|
|
|
this.#encoding,
|
|
|
|
this.#fatal,
|
|
|
|
this.#ignoreBOM,
|
|
|
|
);
|
2022-05-17 09:52:48 -04:00
|
|
|
}
|
2022-09-01 06:51:13 -04:00
|
|
|
return ops.op_encoding_decode(input, this.#rid, options.stream);
|
2021-06-05 17:10:07 -04:00
|
|
|
} finally {
|
2022-06-17 06:49:57 -04:00
|
|
|
if (!options.stream && this.#rid !== null) {
|
2021-06-05 17:10:07 -04:00
|
|
|
core.close(this.#rid);
|
|
|
|
this.#rid = null;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(TextDecoder);
|
2022-02-01 12:06:11 -05:00
|
|
|
const TextDecoderPrototype = TextDecoder.prototype;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
class TextEncoder {
|
|
|
|
constructor() {
|
|
|
|
this[webidl.brand] = webidl.brand;
|
2021-01-05 13:50:40 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/** @returns {string} */
|
2020-07-19 13:49:44 -04:00
|
|
|
get encoding() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
return "utf-8";
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @returns {Uint8Array}
|
|
|
|
*/
|
|
|
|
encode(input = "") {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
const prefix = "Failed to execute 'encode' on 'TextEncoder'";
|
2021-07-06 08:23:31 -04:00
|
|
|
// The WebIDL type of `input` is `USVString`, but `core.encode` already
|
|
|
|
// converts lone surrogates to the replacement character.
|
|
|
|
input = webidl.converters.DOMString(input, {
|
2021-06-05 17:10:07 -04:00
|
|
|
prefix,
|
2021-06-05 19:38:39 -04:00
|
|
|
context: "Argument 1",
|
2020-07-19 13:49:44 -04:00
|
|
|
});
|
2021-06-05 17:10:07 -04:00
|
|
|
return core.encode(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} source
|
|
|
|
* @param {Uint8Array} destination
|
|
|
|
* @returns {TextEncoderEncodeIntoResult}
|
|
|
|
*/
|
|
|
|
encodeInto(source, destination) {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderPrototype);
|
2021-06-05 17:10:07 -04:00
|
|
|
const prefix = "Failed to execute 'encodeInto' on 'TextEncoder'";
|
2021-07-06 08:23:31 -04:00
|
|
|
// The WebIDL type of `source` is `USVString`, but the ops bindings
|
|
|
|
// already convert lone surrogates to the replacement character.
|
|
|
|
source = webidl.converters.DOMString(source, {
|
2021-06-05 17:10:07 -04:00
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
destination = webidl.converters.Uint8Array(destination, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
allowShared: true,
|
|
|
|
});
|
2022-09-17 07:18:15 -04:00
|
|
|
ops.op_encoding_encode_into(source, destination, encodeIntoBuf);
|
|
|
|
return {
|
|
|
|
read: encodeIntoBuf[0],
|
|
|
|
written: encodeIntoBuf[1],
|
|
|
|
};
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 07:18:15 -04:00
|
|
|
const encodeIntoBuf = new Uint32Array(2);
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(TextEncoder);
|
2022-02-01 12:06:11 -05:00
|
|
|
const TextEncoderPrototype = TextEncoder.prototype;
|
2021-06-05 17:10:07 -04:00
|
|
|
|
2021-06-05 21:23:16 -04:00
|
|
|
class TextDecoderStream {
|
|
|
|
/** @type {TextDecoder} */
|
|
|
|
#decoder;
|
|
|
|
/** @type {TransformStream<BufferSource, string>} */
|
|
|
|
#transform;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} label
|
|
|
|
* @param {TextDecoderOptions} options
|
|
|
|
*/
|
|
|
|
constructor(label = "utf-8", options = {}) {
|
|
|
|
const prefix = "Failed to construct 'TextDecoderStream'";
|
|
|
|
label = webidl.converters.DOMString(label, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
options = webidl.converters.TextDecoderOptions(options, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
this.#decoder = new TextDecoder(label, options);
|
|
|
|
this.#transform = new TransformStream({
|
|
|
|
// The transform and flush functions need access to TextDecoderStream's
|
|
|
|
// `this`, so they are defined as functions rather than methods.
|
|
|
|
transform: (chunk, controller) => {
|
|
|
|
try {
|
|
|
|
chunk = webidl.converters.BufferSource(chunk, {
|
|
|
|
allowShared: true,
|
|
|
|
});
|
|
|
|
const decoded = this.#decoder.decode(chunk, { stream: true });
|
|
|
|
if (decoded) {
|
|
|
|
controller.enqueue(decoded);
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseResolve();
|
2021-06-05 21:23:16 -04:00
|
|
|
} catch (err) {
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseReject(err);
|
2021-06-05 21:23:16 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
flush: (controller) => {
|
|
|
|
try {
|
|
|
|
const final = this.#decoder.decode();
|
|
|
|
if (final) {
|
|
|
|
controller.enqueue(final);
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseResolve();
|
2021-06-05 21:23:16 -04:00
|
|
|
} catch (err) {
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseReject(err);
|
2021-06-05 21:23:16 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {string} */
|
|
|
|
get encoding() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#decoder.encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {boolean} */
|
|
|
|
get fatal() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#decoder.fatal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {boolean} */
|
|
|
|
get ignoreBOM() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#decoder.ignoreBOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {ReadableStream<string>} */
|
|
|
|
get readable() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#transform.readable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {WritableStream<BufferSource>} */
|
|
|
|
get writable() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextDecoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#transform.writable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(TextDecoderStream);
|
2022-02-01 12:06:11 -05:00
|
|
|
const TextDecoderStreamPrototype = TextDecoderStream.prototype;
|
2021-06-05 21:23:16 -04:00
|
|
|
|
|
|
|
class TextEncoderStream {
|
|
|
|
/** @type {string | null} */
|
|
|
|
#pendingHighSurrogate = null;
|
|
|
|
/** @type {TransformStream<string, Uint8Array>} */
|
|
|
|
#transform;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.#transform = new TransformStream({
|
|
|
|
// The transform and flush functions need access to TextEncoderStream's
|
|
|
|
// `this`, so they are defined as functions rather than methods.
|
|
|
|
transform: (chunk, controller) => {
|
|
|
|
try {
|
|
|
|
chunk = webidl.converters.DOMString(chunk);
|
2022-01-04 18:42:30 -05:00
|
|
|
if (chunk === "") {
|
|
|
|
return PromiseResolve();
|
|
|
|
}
|
2021-06-05 21:23:16 -04:00
|
|
|
if (this.#pendingHighSurrogate !== null) {
|
|
|
|
chunk = this.#pendingHighSurrogate + chunk;
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
const lastCodeUnit = StringPrototypeCharCodeAt(
|
|
|
|
chunk,
|
|
|
|
chunk.length - 1,
|
|
|
|
);
|
2021-06-05 21:23:16 -04:00
|
|
|
if (0xD800 <= lastCodeUnit && lastCodeUnit <= 0xDBFF) {
|
2021-07-06 08:38:12 -04:00
|
|
|
this.#pendingHighSurrogate = StringPrototypeSlice(chunk, -1);
|
|
|
|
chunk = StringPrototypeSlice(chunk, 0, -1);
|
2021-06-05 21:23:16 -04:00
|
|
|
} else {
|
|
|
|
this.#pendingHighSurrogate = null;
|
|
|
|
}
|
|
|
|
if (chunk) {
|
|
|
|
controller.enqueue(core.encode(chunk));
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseResolve();
|
2021-06-05 21:23:16 -04:00
|
|
|
} catch (err) {
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseReject(err);
|
2021-06-05 21:23:16 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
flush: (controller) => {
|
|
|
|
try {
|
|
|
|
if (this.#pendingHighSurrogate !== null) {
|
|
|
|
controller.enqueue(new Uint8Array([0xEF, 0xBF, 0xBD]));
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseResolve();
|
2021-06-05 21:23:16 -04:00
|
|
|
} catch (err) {
|
2021-07-06 08:38:12 -04:00
|
|
|
return PromiseReject(err);
|
2021-06-05 21:23:16 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {string} */
|
|
|
|
get encoding() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return "utf-8";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {ReadableStream<Uint8Array>} */
|
|
|
|
get readable() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#transform.readable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {WritableStream<string>} */
|
|
|
|
get writable() {
|
2022-02-01 12:06:11 -05:00
|
|
|
webidl.assertBranded(this, TextEncoderStreamPrototype);
|
2021-06-05 21:23:16 -04:00
|
|
|
return this.#transform.writable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(TextEncoderStream);
|
2022-02-01 12:06:11 -05:00
|
|
|
const TextEncoderStreamPrototype = TextEncoderStream.prototype;
|
2021-06-05 21:23:16 -04:00
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter(
|
|
|
|
"TextDecoderOptions",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "fatal",
|
|
|
|
converter: webidl.converters.boolean,
|
|
|
|
defaultValue: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "ignoreBOM",
|
|
|
|
converter: webidl.converters.boolean,
|
|
|
|
defaultValue: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
webidl.converters.TextDecodeOptions = webidl.createDictionaryConverter(
|
|
|
|
"TextDecodeOptions",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "stream",
|
|
|
|
converter: webidl.converters.boolean,
|
|
|
|
defaultValue: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2020-08-07 10:55:02 -04:00
|
|
|
|
2021-04-08 09:05:08 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {Uint8Array} bytes
|
2021-04-08 09:05:08 -04:00
|
|
|
*/
|
|
|
|
function decode(bytes, encoding) {
|
|
|
|
const BOMEncoding = BOMSniff(bytes);
|
|
|
|
let start = 0;
|
|
|
|
if (BOMEncoding !== null) {
|
|
|
|
encoding = BOMEncoding;
|
|
|
|
if (BOMEncoding === "UTF-8") start = 3;
|
|
|
|
else start = 2;
|
|
|
|
}
|
2021-07-06 08:38:12 -04:00
|
|
|
return new TextDecoder(encoding).decode(
|
|
|
|
TypedArrayPrototypeSlice(bytes, start),
|
|
|
|
);
|
2021-04-08 09:05:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {Uint8Array} bytes
|
2021-04-08 09:05:08 -04:00
|
|
|
*/
|
|
|
|
function BOMSniff(bytes) {
|
2021-07-06 08:38:12 -04:00
|
|
|
const BOM = TypedArrayPrototypeSubarray(bytes, 0, 3);
|
2021-04-08 09:05:08 -04:00
|
|
|
if (BOM[0] === 0xEF && BOM[1] === 0xBB && BOM[2] === 0xBF) {
|
|
|
|
return "UTF-8";
|
|
|
|
}
|
|
|
|
if (BOM[0] === 0xFE && BOM[1] === 0xFF) return "UTF-16BE";
|
|
|
|
if (BOM[0] === 0xFF && BOM[1] === 0xFE) return "UTF-16LE";
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
window.__bootstrap.encoding = {
|
|
|
|
TextEncoder,
|
|
|
|
TextDecoder,
|
2021-06-05 21:23:16 -04:00
|
|
|
TextEncoderStream,
|
|
|
|
TextDecoderStream,
|
2021-06-05 17:10:07 -04:00
|
|
|
decode,
|
|
|
|
};
|
2020-07-19 13:49:44 -04:00
|
|
|
})(this);
|