Current section
Files
Jump to
Current section
Files
src/gossamer/text_decoder.ffi.mjs
// src/gossamer/text_decoder.ffi.ts
import * as $textDecoder from "./text_decoder.mjs";
import { fromEncoding } from "./encoding.ffi.mjs";
import { toArray } from "../utils/list.ffi.mjs";
import { toResult } from "../utils/result.ffi.mjs";
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();
var new_ = () => {
return new TextDecoder();
};
var new_with = (label, options) => {
return toResult.fromThrows(
() => new TextDecoder(label, toTextDecoderOptions(options))
);
};
var encoding = (decoder) => {
return fromEncoding(decoder.encoding);
};
var is_fatal = (decoder) => {
return decoder.fatal;
};
var is_ignore_bom = (decoder) => {
return decoder.ignoreBOM;
};
var decode_chunk = (decoder, input) => {
return toResult.fromThrows(() => decoder.decode(input, { stream: true }));
};
var flush = (decoder) => {
return toResult.fromThrows(() => decoder.decode());
};
var decode = (input) => {
return sharedDecoder.decode(input);
};
var decode_with = (input, label, options) => {
return toResult.fromThrows(
() => new TextDecoder(label, toTextDecoderOptions(options)).decode(input)
);
};
export {
decode,
decode_chunk,
decode_with,
encoding,
flush,
is_fatal,
is_ignore_bom,
new_,
new_with,
toTextDecoderOptions
};