Add std.io exact stdin/file/TCP reads, bounded file read-to-end and limited file write/append copies. Use caller slices and resource loans, exact effects, explicit EOF/capacity/limit and confirmed partial progress. No implicit heap, open/close, timeout or new AIR/runtime semantics. Document failure limits and check hosted read errors and a partial external file write under a child-only file-size quota. Integrate normative contracts, RFC, source reference budgets, CLI/profile/package checks and independent byte/count/cursor vectors. Validation: 1027 conformance cases, 20 I/O GC cases, scheduled stress, unit/Quick Reference, formatting, hosted smoke, 55 CLI checks, 111 source coverage constructs and unchanged AIR reference bundle.
21 lines
1.1 KiB
Rust
21 lines
1.1 KiB
Rust
// expect: run
|
|
// result: 42
|
|
// phase: 6
|
|
// spec: docs/spec/16-standard-library.md §2.17
|
|
// grant: src=fs.read:/in
|
|
// grant: dst=fs.write:/out
|
|
// vfs: /in/data=abcd
|
|
// file: /out/data=abc
|
|
module test.io
|
|
import std.io;
|
|
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
|
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
|
}
|
|
fn main(src: cap<fs.read>,dst: cap<fs.write>) -> u64 effects [fs.read,fs.write] {
|
|
let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; var bytes: [u8;4] = [99u8;4];
|
|
match std.io.copy_file(mut input,mut output,mut bytes[1usize..3usize],3usize) { std.io.CopyResult::limit(count) => { assert(count == 3usize); }, std.io.CopyResult::eof(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } }
|
|
assert(bytes[0] == 99u8); assert(bytes[3] == 99u8);
|
|
var tail: [u8;1] = [0u8;1]; exact(std.io.read_exact_file(mut input,mut tail)); assert(tail[0] == 100u8);
|
|
fs.close(move input) or trap; fs.close(move output) or trap; return 42;
|
|
}
|