Skip to main content
Sifr treats every byte/text boundary as an explicit decision. There is no locale-derived default encoding and no implicit byte-to-string coercion. When you open a text file you must name the encoding; when you read raw bytes you get bytes until you call decode yourself. This design prevents an entire class of silent data corruption bugs that plague programs relying on platform locale settings.

Text Files with sifr.io

Use open_text from sifr.io to read or write text files. The encoding= parameter is required:
open(path) and text-mode open(path, "r") without encoding= are intentionally unsupported and raise SIFR-IO-0801 at compile time. Sifr never falls back to a locale-derived default encoding. Always pass an explicit codec descriptor.

Supported Encodings

Import codec descriptors from sifr.encoding: Windows-125x encodings (e.g., windows1252()) are available through Tier 1 support via encoding_rs. Tier 2 CJK and UTF-32 encodings are deferred to a future release.

Binary Files

For binary I/O, open a file without a text mode. Binary reads return bytes directly:
Decode the bytes explicitly when you need text:

Path Operations with sifr.pathlib

sifr.pathlib provides a Path type for constructing, inspecting, and navigating filesystem paths:
Use p.exists() before reading a file to surface a clean boolean check rather than catching IOError:

File and Directory Operations with sifr.os

sifr.os provides low-level filesystem operations. All return typed errors — never raw OS panics:

Putting It Together: Text File Round-Trip

The following example — drawn directly from the Sifr text/i18n demo — shows the complete round-trip pattern: write, read back, and clean up:

Temporary Files

For temporary files, construct a path under the OS temp directory using sifr.os and sifr.pathlib, and clean up explicitly with remove_file. Sifr does not expose a tempfile module; explicit paths and explicit cleanup keep resource lifetimes visible in the ownership graph.
Resource cleanup under task cancellation is part of Sifr’s structured runtime rules. File handles that go out of scope are closed before cancellation evidence is surfaced to the caller.