File input/output: Difference between revisions

Line 2,526:
Reads the entire file into into a list of buffers before writing and returns number of bytes written.
<lang snabel>
let: q io-queueBin list;
'input.txt' rfile read {@q $1 push _} for
0 @q 'output.txt' rwfile @q write $1 _ &+ for
$1 _ &+ for
</lang>
 
Line 2,534 ⟶ 2,535:
<lang snabel>
func: do-write {(
rwfile $1 write yield
{_ yield1} for
)};
Line 2,540 ⟶ 2,541:
func: do-copy {
"Init queue and writer proc"
let: q io-queueBin list;
func: w @q fifo $1 do-write proc;
 
_ rfile read 0 $1 {
"Push to queue and run writer if incoming data"
+? {$ @q $2 push _ len $1 _ +? {w} when
@q $2 push w
} when _ +
} for
"Run writer until done if data left in queue"
@q len +? {&w run} when _
};