Struct std::io::BufferedStreamExperimental
[-]
[+]
[src]
pub struct BufferedStream<S> {
// some fields omitted
}Wraps a Stream and buffers input and output to and from it.
It can be excessively inefficient to work directly with a Stream. For
example, every call to read or write on TcpStream results in a system
call. A BufferedStream keeps in memory buffers of data, making large,
infrequent calls to read and write on the underlying Stream.
The output half will be flushed when this stream is dropped.
Example
fn main() { #![allow(unused_must_use)] use std::io::{BufferedStream, File}; let file = File::open(&Path::new("message.txt")); let mut stream = BufferedStream::new(file); stream.write("hello, world".as_bytes()); stream.flush(); let mut buf = [0, ..100]; match stream.read(&mut buf) { Ok(nread) => println!("Read {} bytes", nread), Err(e) => println!("error reading: {}", e) } }use std::io::{BufferedStream, File}; let file = File::open(&Path::new("message.txt")); let mut stream = BufferedStream::new(file); stream.write("hello, world".as_bytes()); stream.flush(); let mut buf = [0, ..100]; match stream.read(&mut buf) { Ok(nread) => println!("Read {} bytes", nread), Err(e) => println!("error reading: {}", e) }
Methods
impl<S: Stream> BufferedStream<S>
fn with_capacities(reader_cap: uint, writer_cap: uint, inner: S) -> BufferedStream<S>
Creates a new buffered stream with explicitly listed capacities for the reader/writer buffer.
fn new(inner: S) -> BufferedStream<S>
Creates a new buffered stream with the default reader/writer buffer capacities.
fn get_ref(&self) -> &S
Gets a reference to the underlying stream.
fn get_mut(&mut self) -> &mut S
Gets a mutable reference to the underlying stream.
Warning
It is inadvisable to read directly from or write directly to the underlying stream.
fn into_inner(self) -> S
Unwraps this BufferedStream, returning the underlying stream.
The internal buffer is flushed before returning the stream. Any leftover data in the read buffer is lost.
fn unwrap(self) -> S
Deprecated, use into_inner() instead