Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,26 @@
|
||||
module io
|
||||
|
||||
// CopySettings provides additional options to io.cp
|
||||
@[params]
|
||||
pub struct CopySettings {
|
||||
pub mut:
|
||||
buffer_size int = 64 * 1024 // The buffer size used during the copying. A larger buffer is more performant, but uses more RAM.
|
||||
}
|
||||
|
||||
// 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.
|
||||
@[manualfree]
|
||||
pub fn cp(mut src Reader, mut dst Writer, params CopySettings) ! {
|
||||
mut buf := []u8{len: params.buffer_size}
|
||||
defer {
|
||||
unsafe {
|
||||
buf.free()
|
||||
}
|
||||
}
|
||||
for {
|
||||
bytes := src.read(mut buf) or { break }
|
||||
dst.write(buf[..bytes]) or { return err }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user