Struct std::old_io::BufferedStreamUnstable [-] [+] [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::old_io::{BufferedStream, File}; let file = File::open(&Path::new("message.txt")); let mut stream = BufferedStream::new(file); stream.write_all("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::old_io::{BufferedStream, File};

let file = File::open(&Path::new("message.txt"));
let mut stream = BufferedStream::new(file);

stream.write_all("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: usize, writer_cap: usize, 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.

Trait Implementations

impl<S> Debug for BufferedStream<S> where S: Debug

fn fmt(&self, fmt: &mut Formatter) -> Result

impl<S: Stream> Buffer for BufferedStream<S>

fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]>

fn consume(&mut self, amt: usize)

fn read_line(&mut self) -> IoResult<String>

fn read_until(&mut self, byte: u8) -> IoResult<Vec<u8>>

fn read_char(&mut self) -> IoResult<char>

impl<S: Stream> Reader for BufferedStream<S>

fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>

fn read_at_least(&mut self, min: usize, buf: &mut [u8]) -> IoResult<usize>

fn read_byte(&mut self) -> IoResult<u8>

fn push(&mut self, len: usize, buf: &mut Vec<u8>) -> IoResult<usize>

fn push_at_least(&mut self, min: usize, len: usize, buf: &mut Vec<u8>) -> IoResult<usize>

fn read_exact(&mut self, len: usize) -> IoResult<Vec<u8>>

fn read_to_end(&mut self) -> IoResult<Vec<u8>>

fn read_to_string(&mut self) -> IoResult<String>

fn read_le_uint_n(&mut self, nbytes: usize) -> IoResult<u64>

fn read_le_int_n(&mut self, nbytes: usize) -> IoResult<i64>

fn read_be_uint_n(&mut self, nbytes: usize) -> IoResult<u64>

fn read_be_int_n(&mut self, nbytes: usize) -> IoResult<i64>

fn read_le_uint(&mut self) -> IoResult<usize>

fn read_le_int(&mut self) -> IoResult<isize>

fn read_be_uint(&mut self) -> IoResult<usize>

fn read_be_int(&mut self) -> IoResult<isize>

fn read_be_u64(&mut self) -> IoResult<u64>

fn read_be_u32(&mut self) -> IoResult<u32>

fn read_be_u16(&mut self) -> IoResult<u16>

fn read_be_i64(&mut self) -> IoResult<i64>

fn read_be_i32(&mut self) -> IoResult<i32>

fn read_be_i16(&mut self) -> IoResult<i16>

fn read_be_f64(&mut self) -> IoResult<f64>

fn read_be_f32(&mut self) -> IoResult<f32>

fn read_le_u64(&mut self) -> IoResult<u64>

fn read_le_u32(&mut self) -> IoResult<u32>

fn read_le_u16(&mut self) -> IoResult<u16>

fn read_le_i64(&mut self) -> IoResult<i64>

fn read_le_i32(&mut self) -> IoResult<i32>

fn read_le_i16(&mut self) -> IoResult<i16>

fn read_le_f64(&mut self) -> IoResult<f64>

fn read_le_f32(&mut self) -> IoResult<f32>

fn read_u8(&mut self) -> IoResult<u8>

fn read_i8(&mut self) -> IoResult<i8>

impl<S: Stream> Writer for BufferedStream<S>

fn write_all(&mut self, buf: &[u8]) -> IoResult<()>

fn flush(&mut self) -> IoResult<()>

fn write(&mut self, buf: &[u8]) -> IoResult<()>

fn write_fmt(&mut self, fmt: Arguments) -> IoResult<()>

fn write_str(&mut self, s: &str) -> IoResult<()>

fn write_line(&mut self, s: &str) -> IoResult<()>

fn write_char(&mut self, c: char) -> IoResult<()>

fn write_int(&mut self, n: isize) -> IoResult<()>

fn write_uint(&mut self, n: usize) -> IoResult<()>

fn write_le_uint(&mut self, n: usize) -> IoResult<()>

fn write_le_int(&mut self, n: isize) -> IoResult<()>

fn write_be_uint(&mut self, n: usize) -> IoResult<()>

fn write_be_int(&mut self, n: isize) -> IoResult<()>

fn write_be_u64(&mut self, n: u64) -> IoResult<()>

fn write_be_u32(&mut self, n: u32) -> IoResult<()>

fn write_be_u16(&mut self, n: u16) -> IoResult<()>

fn write_be_i64(&mut self, n: i64) -> IoResult<()>

fn write_be_i32(&mut self, n: i32) -> IoResult<()>

fn write_be_i16(&mut self, n: i16) -> IoResult<()>

fn write_be_f64(&mut self, f: f64) -> IoResult<()>

fn write_be_f32(&mut self, f: f32) -> IoResult<()>

fn write_le_u64(&mut self, n: u64) -> IoResult<()>

fn write_le_u32(&mut self, n: u32) -> IoResult<()>

fn write_le_u16(&mut self, n: u16) -> IoResult<()>

fn write_le_i64(&mut self, n: i64) -> IoResult<()>

fn write_le_i32(&mut self, n: i32) -> IoResult<()>

fn write_le_i16(&mut self, n: i16) -> IoResult<()>

fn write_le_f64(&mut self, f: f64) -> IoResult<()>

fn write_le_f32(&mut self, f: f32) -> IoResult<()>

fn write_u8(&mut self, n: u8) -> IoResult<()>

fn write_i8(&mut self, n: i8) -> IoResult<()>