hare

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

drain.ha (423B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // Reads an entire stream into a []u8. The caller must free the return value.
      5 // Note that this function will never return if the handle is infinite.
      6 export fn drain(in: handle) ([]u8 | error) = {
      7 	let sink: []u8 = [];
      8 	static let buf: [4096]u8 = [0...];
      9 
     10 	for (let n => read(in, buf[..])?) {
     11 		append(sink, buf[..n]...);
     12 	};
     13 	return sink;
     14 };