shithub: mc

ref: 152b881475d2c11fc183669d3d57ed6ac201ef0b
dir: /lib/bio/test/bio-write.myr/

View raw version
use std
use bio

const main = {
	var i
	var f
	/* Must be bigger than a bio buffer (ie, > 64k) */
	var buf : byte[64*1024]

	std.mkpath("tmpout")
	match bio.create("tmpout/test-write", bio.Wr, 0o644)
	| `std.Ok bio:	f = bio
	| `std.Err m:	std.fatal("Unable to open data file: {}", m)
	;;

	/* write a 5 byte chunk */
	bio.write(f, "test\n")

	/* again */
	bio.write(f, "test\n")

	/* write a 64k chunk */
	for i = 0; i < 64*1024; i++
		buf[i] = 0x31
	;;
	bio.write(f, buf[:])

	/* final message after a big burst */
	bio.write(f, "goodbye\n")
	bio.flush(f)

	/* and test for flush on close */
	bio.close(f);
}