io: make io.cp use chunks (#9877)

pull/9887/head
Louis Schmieder 2021-04-26 08:59:23 +02:00 committed by GitHub
parent 7acb48df83
commit f5ce9388de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -1,15 +1,16 @@
module io
const (
buf_max_len = 5 * 1024
buf_max_len = 1024
)
pub fn cp(dst Writer, src Reader) ? {
mut buf := read_all(reader: src) or {
return err
}
dst.write(buf) or {
return
mut buf := []byte{len: buf_max_len}
for {
len := src.read(mut buf) or { break }
dst.write(buf[..len]) or {
return err
}
}
unsafe {
buf.free()