summaryrefslogtreecommitdiff
path: root/libbio/test/bio-read.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
commit20bb032dc16ab0a0a20e9a5705738c797ac4b3da (patch)
tree015f8be7a1d1d99e09e682c35956538ebb57cf50 /libbio/test/bio-read.myr
parentac02d84497997778d2c9680f5c7fc26b9814f62c (diff)
downloadmc-20bb032dc16ab0a0a20e9a5705738c797ac4b3da.tar.gz
Add code to subdir in preparation for merging with mc.
Diffstat (limited to 'libbio/test/bio-read.myr')
-rw-r--r--libbio/test/bio-read.myr46
1 files changed, 46 insertions, 0 deletions
diff --git a/libbio/test/bio-read.myr b/libbio/test/bio-read.myr
new file mode 100644
index 0000000..eafdb4a
--- /dev/null
+++ b/libbio/test/bio-read.myr
@@ -0,0 +1,46 @@
+use std
+use bio
+
+const main = {
+ var f
+ /* Must be bigger than a bio buffer (ie, > 64k) */
+ var buf : byte[64*1024]
+ var b
+
+ match bio.open("data/datafile", bio.Rd)
+ | `std.Some bio: f = bio
+ | `std.None: std.fatal(1, "Unable to open data file")
+ ;;
+
+ /* read a 4 byte chunk j*/
+ b = r(f, buf[:4])
+ std.write(1, b)
+ std.write(1, "\n")
+
+ /* read the next 32 bytes */
+ b = r(f, buf[:32])
+ std.write(1, b)
+ std.write(1, "\n")
+
+ /* read a 64k chunk */
+ b = r(f, buf[:])
+ std.write(1, b)
+ std.write(1, "\n")
+
+ /* read to EOF */
+ b = r(f, buf[:])
+ std.write(1, b)
+ std.write(1, "\n")
+
+ /* and fail */
+ b = r(f, buf[:])
+
+ bio.close(f)
+}
+
+const r = {f, buf
+ match bio.read(f, buf)
+ | `std.Some b: -> b
+ | `std.None: std.put("eof\n")
+ ;;
+}