Current section
Files
Jump to
Current section
Files
src/gossamer/text_decoder_stream.ffi.mjs
// src/gossamer/encoding.ts
import * as $enc from "./encoding.mjs";
function fromEncoding(value) {
switch (value) {
case "utf-8":
return $enc.Encoding$Utf8();
default:
return $enc.Encoding$Other(value);
}
}
// src/gossamer/text_decoder.ffi.ts
import * as $textDecoder from "./text_decoder.mjs";
// src/utils/list.ts
import {
List$Empty,
List$isNonEmpty,
List$NonEmpty,
List$NonEmpty$first,
List$NonEmpty$rest
} from "../../prelude.mjs";
function toArray(list) {
const array = [];
let current = list;
while (List$isNonEmpty(current)) {
array.push(List$NonEmpty$first(current));
current = List$NonEmpty$rest(current);
}
return array;
}
// src/utils/result.ts
import { Result$Error, Result$Ok } from "../../prelude.mjs";
function toResult(value) {
return value === null || value === void 0 ? Result$Error(void 0) : Result$Ok(value);
}
toResult.fromThrows = function(throws) {
try {
return Result$Ok(throws());
} catch (error) {
return Result$Error(
error instanceof Error ? error.message : String(error)
);
}
};
toResult.fromPromise = function(promise) {
return promise.then(
(value) => Result$Ok(value),
(error) => Result$Error(error instanceof Error ? error.message : String(error))
);
};
// src/gossamer/text_decoder.ffi.ts
function toTextDecoderOptions(options) {
const result = {};
for (const option of toArray(options)) {
if ($textDecoder.TextDecoderOption$isFatal(option)) {
result.fatal = true;
} else if ($textDecoder.TextDecoderOption$isIgnoreBom(option)) {
result.ignoreBOM = true;
}
}
return result;
}
var sharedDecoder = new TextDecoder();
// src/gossamer/text_decoder_stream.ffi.ts
var new_ = () => {
return new TextDecoderStream();
};
var new_with = (label, options) => {
return toResult.fromThrows(
() => new TextDecoderStream(label, toTextDecoderOptions(options))
);
};
var readable = (decoder) => {
return decoder.readable;
};
var writable = (decoder) => {
return decoder.writable;
};
var encoding = (decoder) => {
return fromEncoding(decoder.encoding);
};
var is_fatal = (decoder) => {
return decoder.fatal;
};
var is_ignore_bom = (decoder) => {
return decoder.ignoreBOM;
};
export {
encoding,
is_fatal,
is_ignore_bom,
new_,
new_with,
readable,
writable
};