import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/take";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/definition";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/drop";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_5 from "@effect/core/stream/Stream/operations/via";
import { Utf8 } from "@effect/core/stream/Stream/operations/_internal/bom";
import { utf8DecodeNoBom } from "@effect/core/stream/Stream/operations/_internal/utf8DecodeNoBom";
import { utfDecodeDetectingBom } from "@effect/core/stream/Stream/operations/_internal/utfDecodeDetectingBom"; // TODO(Mike/Max): look into utf16 and utf32 encodings

/**
 * Determines the right encoder to use based on the Byte Order Mark (BOM). If it
 * doesn't detect one, it defaults to utf8Decode.
 *
 * @tsplus fluent ets/Stream utfDecode
 */

export function utfDecode(self, __tsplusTrace) {
  return tsplus_module_5.via_(self, utfDecodeDetectingBom(4, bytes => tsplus_module_2.corresponds_(tsplus_module_1.take_(bytes, 3), Utf8, (a, b) => a === b) ? tsplus_module_4.make(tsplus_module_3.drop_(bytes, 3), utf8DecodeNoBom) : tsplus_module_4.make(bytes, utf8DecodeNoBom), __tsplusTrace));
}
//# sourceMappingURL=utfDecode.mjs.map