mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
@@ -44,7 +44,7 @@ mut:
|
||||
|
||||
// read_all reads all bytes from a reader until either a 0 length read
|
||||
// or if read_to_end_of_stream is true then the end of the stream (`none`)
|
||||
pub fn read_all(config ReadAllConfig) ?[]u8 {
|
||||
pub fn read_all(config ReadAllConfig) ![]u8 {
|
||||
mut r := config.reader
|
||||
read_till_eof := config.read_to_end_of_stream
|
||||
|
||||
@@ -65,11 +65,11 @@ pub fn read_all(config ReadAllConfig) ?[]u8 {
|
||||
|
||||
// read_any reads any available bytes from a reader
|
||||
// (until the reader returns a read of 0 length)
|
||||
pub fn read_any(mut r Reader) ?[]u8 {
|
||||
pub fn read_any(mut r Reader) ![]u8 {
|
||||
mut b := []u8{len: io.read_all_len}
|
||||
mut read := 0
|
||||
for {
|
||||
new_read := r.read(mut b[read..]) or { return none }
|
||||
new_read := r.read(mut b[read..]) or { return error('none') }
|
||||
read += new_read
|
||||
if new_read == 0 {
|
||||
break
|
||||
@@ -83,5 +83,5 @@ pub fn read_any(mut r Reader) ?[]u8 {
|
||||
|
||||
// RandomReader represents a stream of data that can be read from at a random location
|
||||
pub interface RandomReader {
|
||||
read_from(pos u64, mut buf []u8) ?int
|
||||
read_from(pos u64, mut buf []u8) !int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user