The following operations can be performed on file streams.
closeG.f. method
close file-stream #key abort wait? => ()
#t), then a close request is merely enqueued to be performed after all pending write operations; otherwise the file is closed immediately and all underlying system resources held on behalf of the stream are freed.
#f) is true, the file is flushed to the physical disk before closing -- this guarantees that no data is retained in the operating system's write cache. Calling close with synchronize? #t is equivalent to calling force-output with synchronize? true and then calling close.
Statement macro
wait-for-io-completion file-stream => ()
write or close operations to complete and signals any queued errors. If file-stream is not asynchronous, returns immediately.
Statement macro
with-open-file (stream-var = filename, #rest keys) body end => values
close upon exiting body.
make method on <file-stream>.
foo.text as a <byte-vector>:
with-open-file (fs = "foo.text", element-type: <byte>) read-to-end(fs) end;
begin
let hidden-fs = #f; // In case the user bashes fs variable
block ()
hidden-fs := make(<file-stream>,
locator: "foo.text", element-type: <byte>);
let fs = hidden-fs;
read-to-end(fs);
cleanup
if (hidden-fs) close(hidden-fs) end;
end block;
end;