The [file->doWithClose] method takes a block of code and executes it and it makes sure that the [file] object the method is called on closes the file. The file will be closed if there is an error as well as if the code block successfully runs.
local(f) = file(...)
#f->doWithClose => {
}
The code below reads the contents of a file and outputs it to a web page encoding the line breaks as '<br>' tags
Code
local(my_file) = file('test.txt')
#my_file->doWithClose => {^
encode_break(#my_file->readBytes->asString)
^}
Result
"Great Scott!"
"I know. This is heavy."
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments