Byte-file and text-file helpers for contiguous byte storage and UTF-8 string values.
loadFile and saveFile operate on raw bytes.loadString, saveString, and appendString operate on the current UTF-8 byte sequence of the supplied or returned String value.addTerminator and String.makeStringView, so file-name inputs accept StringView, Text, and String.saveString and appendString normalize their text argument through String.makeStringView.SEEK_SET, SEEK_CUR, and SEEK_END are exposed because the implementation uses whole-file seeks internally.(errnum -- textView)Returns one StringView for the supplied error number.
(name -- result)Loads one whole file into a byte-array result record.
result and data.data holds the loaded bytes as Nat8 Array.result holds one error string; success leaves it empty.data is not guaranteed to represent the whole file contents.(name data -- result)Saves contiguous byte storage to one file.
data supplies bytes through its data and size selectors.String; success returns the empty string.(name -- result)Loads one whole file into a string result record.
success and data.success reports whether the whole operation succeeded.data holds the loaded String.String, but String.size excludes that terminator.data is not guaranteed to represent the whole file contents.(name text -- success)Saves text bytes to one file and reports whether the whole operation succeeded.
(name text -- success)Appends text bytes to the end of one file and reports whether the whole operation succeeded.
"file" use
"control" use
{} () {} [
"sample.txt" "alpha" saveString printStack _:;
"sample.txt" loadString.success printStack _:;
"sample.txt" loadString.data.size printStack _:;
"sample.txt" "beta" appendString printStack _:;
] "main" exportFunction
Cond
Cond Cref
Int32
Cond
"file" use
"String" use
"control" use
{} Int32 {} [
"sample.txt" "alpha" saveString drop
"sample.txt" "beta" appendString drop
loaded: "sample.txt" loadString;
loaded.data print
0
] "main" exportFunction
alphabeta