hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/lib/text.json
{
"name": "hydra.core.lib.text",
"metadata": {
"description": "Primitives in the hydra.core.lib.text module.",
"comments": [
"Text encoding.",
"These primitives are the canonical UTF-8 conversions between Hydra's binary and string types, for interpreting bytes as text. They are distinct from hydra.lib.literals.binaryToBase64 / base64ToBinary, which are total, round-trippable base64 conversions for embedding arbitrary binary in a string context (e.g. a JSON value) -- use those when the bytes are not necessarily text.",
"Both text primitives are pure: file and other byte-oriented I/O is performed separately (see hydra.lib.files), with encoding and decoding applied before or after."],
"seeAlso": [],
"provisions": []},
"dependencies": [{"module": "hydra.core.model"}, {"module": "hydra.core.packaging"}, {"module": "hydra.core.typing"}],
"definitions": [
{
"primitive": {
"name": "hydra.core.lib.text.decodeUtf8",
"metadata": {
"description": "Decode a sequence of bytes as UTF-8 text.",
"comments": [
"decodeUtf8(bytes) attempts to interpret bytes as a UTF-8 encoded string. A byte sequence which is not valid UTF-8 yields left(message), where message is a host-provided description of the decoding failure; a successful decode yields right(text).",
"Pairs with hydra.core.lib.files.readFile, which returns raw bytes."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.text.decodeUtf8.decodesValidUtf8",
"kind": "requirement",
"statement": "decodeUtf8 decodes a valid UTF-8 byte sequence to its text, wrapped in right, including the empty byte sequence, ASCII-only text, and multi-byte (non-ASCII) text."},
{
"name": "hydra.core.lib.text.decodeUtf8.leftOnInvalidUtf8",
"kind": "requirement",
"statement": "decodeUtf8 returns left(message) when the byte sequence is not valid UTF-8, such as a lone continuation byte."}]},
"signature": {
"typeParameters": [],
"parameters": [
{"name": "bytes", "description": "the byte sequence to decode as UTF-8", "type": {"literal": "binary"}, "isLazy": false}],
"result": {"type": {"either": {"left": {"literal": "string"}, "right": {"literal": "string"}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.text.encodeUtf8",
"metadata": {
"description": "Encode text as a sequence of UTF-8 bytes.",
"comments": [
"encodeUtf8(text) returns the UTF-8 encoding of text as raw bytes. Total: every Hydra string is valid Unicode and therefore always encodes.",
"Pairs with hydra.core.lib.files.writeFile, which expects raw bytes."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.text.encodeUtf8.encodesExactUtf8Bytes",
"kind": "requirement",
"statement": "encodeUtf8 returns the exact UTF-8 byte sequence for the given text, for the empty string, ASCII-only text, and multi-byte (non-ASCII) text."}]},
"signature": {
"typeParameters": [],
"parameters": [{"name": "text", "description": "the text to encode as UTF-8", "type": {"literal": "string"}, "isLazy": false}],
"result": {"type": {"literal": "binary"}}},
"isPure": true,
"isTotal": true}}]}