hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 43e41da281f9f1831578876a23f5a20f386fed3b
parent 936a79ac39fedb272bd4c68e143ea28d6a76b565
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 20 Apr 2021 10:26:15 -0400

io: add io::drain

Diffstat:
Aio/drain.ha | 12++++++++++++
Mscripts/gen-stdlib | 1+
Mstdlib.mk | 2++
3 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/io/drain.ha b/io/drain.ha @@ -0,0 +1,12 @@ +// Reads an entire stream into a []u8. +export fn drain(in: *io::stream) ([]u8 | io::error) = { + let sink: []u8 = []; + static let buf: [4096]u8 = [0...]; + for (true) { + match (read(in, buf[..])?) { + n: size => append(sink, buf[..n]...), + _: EOF => break, + }; + }; + return sink; +}; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -426,6 +426,7 @@ gensrcs_io() { gen_srcs io \ 'arch$(ARCH).ha' \ copy.ha \ + drain.ha \ limit.ha \ 'println$(PLATFORM).ha' \ stream.ha \ diff --git a/stdlib.mk b/stdlib.mk @@ -590,6 +590,7 @@ $(HARECACHE)/hash/fnv/hash_fnv.ssa: $(stdlib_hash_fnv_srcs) $(stdlib_rt) $(stdli stdlib_io_srcs= \ $(STDLIB)/io/arch$(ARCH).ha \ $(STDLIB)/io/copy.ha \ + $(STDLIB)/io/drain.ha \ $(STDLIB)/io/limit.ha \ $(STDLIB)/io/println$(PLATFORM).ha \ $(STDLIB)/io/stream.ha \ @@ -1467,6 +1468,7 @@ $(TESTCACHE)/hash/fnv/hash_fnv.ssa: $(testlib_hash_fnv_srcs) $(testlib_rt) $(tes testlib_io_srcs= \ $(STDLIB)/io/arch$(ARCH).ha \ $(STDLIB)/io/copy.ha \ + $(STDLIB)/io/drain.ha \ $(STDLIB)/io/limit.ha \ $(STDLIB)/io/println$(PLATFORM).ha \ $(STDLIB)/io/stream.ha \