import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/pipeTo";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/suspend";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/isEmpty";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/unit";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/readWith";
import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
import { stringChunkFrom } from "@effect/core/stream/Stream/operations/_internal/stringChunkFrom";
export function textDecodeUsing(charset, __tsplusTrace) {
  return stream => {
    void 0;
    return new StreamInternal(tsplus_module_2.suspend(() => tsplus_module_1.pipeTo_(stream.channel, () => transform(charset))));
  };
}

function transform(charset) {
  return tsplus_module_7.readWith(received => tsplus_module_3.isEmpty(received) ? transform(charset) : tsplus_module_4.write(() => stringChunkFrom(received, charset)), err => tsplus_module_5.fail(() => err), () => tsplus_module_6.unit);
}
//# sourceMappingURL=textDecodeUsing.mjs.map