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
| Function | Returns | Description |
|---|---|---|
crypto.base64_encode(b) | Str | Encode bytes as base64 string |
crypto.base64_decode(s) | Bytes | Decode base64 string to bytes |
crypto.hex_encode(b) | Str | Encode bytes as hex string |
crypto.hex_decode(s) | Bytes | Decode 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
| Module | Function | Description |
|---|---|---|
fs | read_bytes(path) | Read file as Bytes |
fs | write_bytes(path, data) | Write Bytes to file |
http | response .body_bytes() | HTTP response body as Bytes |
crypto | random_bytes(n) | Generate n random bytes |