commit 368aafe3b7f7d2793c926ef44a79a48f88a5741f
parent fc0aa8058d7839981e5ae501c4d5d9f61e5a44df
Author: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Date: Wed, 8 Dec 2021 22:42:09 +0100
encoding/base64: Use error propagation in decodestream_reader()
For any errors encountered during io::read() we just return it, so we
might as well use error propagation.
Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Diffstat:
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/encoding/base64/base64.ha b/encoding/base64/base64.ha
@@ -280,7 +280,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
// If we get here, we have pushed out all cached bytes and are ready to
// read some more. Reset the internal buffer here.
buf = [INVALID_OR_PAD...];
- for (true) match (io::read(s.input, buf)) {
+ for (true) match (io::read(s.input, buf)?) {
case size =>
for (let i = 0z; i < 2; i += 1) {
if (decoder[buf[i]] == INVALID_OR_PAD) {
@@ -301,7 +301,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
s.avail += 1;
// End of stream...
let extra: []u8 = [0];
- match (io::read(s.input, extra)) {
+ match (io::read(s.input, extra)?) {
case size =>
return errors::invalid;
case io::EOF =>
@@ -312,8 +312,6 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
s.avail = 0;
};
break;
- case let err: io::error =>
- return err;
};
} else {
buf[2] = decoder[buf[2]];
@@ -329,7 +327,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
];
s.avail += 2;
let extra: []u8 = [0];
- match (io::read(s.input, extra)) {
+ match (io::read(s.input, extra)?) {
case size =>
return errors::invalid;
case io::EOF =>
@@ -341,8 +339,6 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
s.waseof = true;
z += n;
break;
- case let err: io::error =>
- return err;
};
} else {
buf[3] = decoder[buf[3]];
@@ -371,8 +367,6 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
return io::EOF;
};
break;
- case let err: io::error =>
- return err;
};
return z;
};
@@ -399,14 +393,12 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
let out: []u8 = [];
defer free(out);
- for (true) match (io::read(&dec, buf)) {
+ for (true) match (io::read(&dec, buf)!) {
case let z: size =>
append(out, buf[0]);
assert(z == 1);
case io::EOF =>
break;
- case let err: io::error =>
- abort();
};
assert(bytes::equal(out, strings::toutf8(expected)));
@@ -427,13 +419,11 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) =
let out: []u8 = [];
defer free(out);
- for (true) match (io::read(&dec, buf)) {
+ for (true) match (io::read(&dec, buf)!) {
case let z: size =>
append(out, buf[..z]...);
case io::EOF =>
break;
- case let err: io::error =>
- abort();
};
assert(bytes::equal(out, strings::toutf8(expected)));