Separating Read-Only Inputs from Writable Results
Using an input stream for reading and a different output stream for writing makes file ownership and observed effects easier to review.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a mistaken source operation
An import reads rows.csv and produces cleaned.csv. Opening the first in truncating mode destroys the data before a row is read. File open modes define the observed effect of that call.
Protect completed results
If the source and result can refer to the same file through different paths, confirm the program supports that case. Compute a separate complete output under a clear replacement contract when preserving the source until success matters.[1]
Protect the source from accidental write semantics
A conversion reads a source data file and emits a transformed copy. Opening the source as read-only makes its edit intent clear. An ordinary write-mode open on the same path could truncate it even before writing. Keep input and output destinations distinct in the interface. See file open modes.
Source bytes A,B,C
Open source for reading → source retained
Produce candidate output separately
Replace destination only if authorized by the calling contract
Verify ownership of handles passed between helpers
A converter accepting a pre-opened reader can leave closure to its owner if the contract says so. A converter opening a path usually owns the handle. Test caller visibility after a conversion error.