summaryrefslogtreecommitdiff
path: root/lib/bio/test/bio-write.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bio/test/bio-write.myr')
-rw-r--r--lib/bio/test/bio-write.myr33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/bio/test/bio-write.myr b/lib/bio/test/bio-write.myr
new file mode 100644
index 0000000..cbe7441
--- /dev/null
+++ b/lib/bio/test/bio-write.myr
@@ -0,0 +1,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);
+}