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:
Supported Encodings
Import codec descriptors fromsifr.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 returnbytes directly:
Path Operations with sifr.pathlib
sifr.pathlib provides a Path type for constructing, inspecting, and navigating filesystem paths:
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 usingsifr.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.
