GitHub

API reference for Bytes.

Bytes with their content type and length (Effect's Uint8Array body). text is the text they were encoded from, if any.

Attributes

AttributeTypeDescription
bodybytes
content_typestr
content_lengthint
textstr | None = None
tagLiteral['Bytes'] = 'Bytes'

Functions

__init__

__init__(body, content_type, content_length, text=None) -> None
ParameterTypeDescription
bodybytes
content_typestr
content_lengthint
textstr | None = None

to_json

to_json() -> dict[str, object]

Returns dict[str, object]

def to_json(self) -> dict[str, object]:
    readable = self.content_type.startswith("text/") or self.content_type.endswith("json")
    return {
        "_id": "effect/HttpBody",
        "_tag": "Bytes",
        "body": self.body.decode("utf-8", "replace")
        if readable
        else f"bytes({len(self.body)})",
        "content_type": self.content_type,
        "content_length": self.content_length,
    }