summaryrefslogtreecommitdiff
path: root/libbio/test/bio-write.myr
blob: cbe7441f67fee782f1dee9ab61d855e9c19c53ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std
use bio

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

	match bio.create("tmpout/test-write", bio.Wr, 0o644)
	| `std.Some bio:	f = bio
	| `std.None:	std.fatal(1, "Unable to open data file")
	;;

	/* 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);
}