Tcl channels: files, fconfigure, encodings and binary data
11 steps · about 3 h 25 min · Intermediate
- File Access 101 (tutorial, Tcl official tutorial, 20 min)
Start with the basics of open, gets, puts, read and close, because every channel option builds on these.
- Input & output in Tcl (article, ZetCode, 15 min)
It introduces the idea that stdin, stdout and files are all channels, with short worked scripts.
- Tcl open - File Operations in Tcl (article, ZetCode, 15 min)
It covers access modes, permissions and the rb flag, so you see how binary mode first appears at open time.
- How do I read and write files in Tcl (reference, Tcler's Wiki, 15 min)
It collects common idioms and pitfalls for line-by-line reading and whole-file reading.
- fconfigure manual page - Tcl Built-In Commands (doc, tcl.tk, 30 min)
This is the official reference for -encoding, -translation, -blocking and the other channel options.
- Tcl Built-In Commands - fconfigure manual page (doc, tcl-lang.org, 15 min)
Its PPM image example shows a channel switching from text mode to binary mode part-way through a read.
- encoding - the Tcler's Wiki! (reference, Tcler's Wiki, 10 min)
Practical examples such as cp1252 conversion help you debug garbled text.
- Working with binary data (reference, Tcler's Wiki, 20 min)
It explains why -translation binary is safer than -encoding binary alone, and shows a full write-then-read round trip.
- binary manual page - Tcl Built-In Commands (doc, tcl-lang.org, 35 min)
Read this once your channels are in binary mode, to learn the format and scan field codes, endianness and unsigned flags.
- Tcl binary - Binary Data Manipulation in Tcl (article, ZetCode, 15 min)
Short runnable examples of format, scan and base64 encoding make the manual page easier to follow.
- binary scan (reference, Tcler's Wiki, 15 min)
It covers the signed-versus-unsigned trap and bit-field edge cases that you tend to hit in real file formats.