2021-04-25 21:22:33 +03:00
|
|
|
module io
|
|
|
|
|
|
|
|
const (
|
2021-04-26 09:59:23 +03:00
|
|
|
buf_max_len = 1024
|
2021-04-25 21:22:33 +03:00
|
|
|
)
|
|
|
|
|
2023-01-25 23:03:20 +03:00
|
|
|
// cp copies from `src` to `dst` by allocating
|
|
|
|
// a maximum of 1024 bytes buffer for reading
|
|
|
|
// until either EOF is reached on `src` or an error occurs.
|
|
|
|
// An error is returned if an error is encountered during write.
|
2022-10-16 09:28:57 +03:00
|
|
|
pub fn cp(mut src Reader, mut dst Writer) ! {
|
2022-04-15 15:35:35 +03:00
|
|
|
mut buf := []u8{len: io.buf_max_len}
|
2021-04-26 09:59:23 +03:00
|
|
|
for {
|
|
|
|
len := src.read(mut buf) or { break }
|
2021-05-08 13:32:29 +03:00
|
|
|
dst.write(buf[..len]) or { return err }
|
2021-04-25 21:22:33 +03:00
|
|
|
}
|
|
|
|
unsafe {
|
|
|
|
buf.free()
|
|
|
|
}
|
|
|
|
}
|