Function little::stream::buf_copy
[−]
[src]
pub fn buf_copy<I, O>(buf: &mut [u8], reader: &mut I, writer: &mut O) -> Result<u64, Error> where I: Read, O: Write
Copy all bytes from reader
to writer
using buf
.
Example
use little::stream; use std::io::{ Cursor, Read }; let data: &[u8] = b"it is interesting"; let mut reader = Cursor::new(data); let mut writer = Vec::new(); let mut buf = [0; 4]; // note the buffer is smaller stream::buf_copy(&mut buf, &mut reader.take(5), &mut writer).unwrap(); assert_eq!("it is", String::from_utf8_lossy(&writer[..]));