Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.

Bytes

The Bytes type represents binary data. It is used across the filesystem, HTTP, and crypto modules for binary I/O. The bytes module is not needed for basic usage - Bytes is a built-in type - but it provides encoding and decoding utilities.

import crypto
import fs

# Binary file I/O
let raw: Bytes = fs.read_bytes("image.png").unwrap()
fs.write_bytes("copy.png", raw).unwrap()

# Crypto operations accept and return Bytes
let hash = crypto.sha256(raw)
print(hash.hex())

Encoding

FunctionReturnsDescription
crypto.base64_encode(b)StrEncode bytes as base64 string
crypto.base64_decode(s)BytesDecode base64 string to bytes
crypto.hex_encode(b)StrEncode bytes as hex string
crypto.hex_decode(s)BytesDecode hex string to bytes

String convenience variants (base64_encode_str, hex_encode_str, etc.) accept and return Str for text-only workflows.

Binary I/O

ModuleFunctionDescription
fsread_bytes(path)Read file as Bytes
fswrite_bytes(path, data)Write Bytes to file
httpresponse .body_bytes()HTTP response body as Bytes
cryptorandom_bytes(n)Generate n random bytes