Basic input/output

Type fd_t

type fd_t = c_int

Enum FileFlag

Variants

Enum SeekStyle

Variants

Enum WriterType

Variants

Struct BytesReader

pub struct BytesReader<'self> {
    bytes: &'self [u8],
    mut pos: uint,
}

Struct BytesWriter

pub struct BytesWriter {
    mut bytes: ~[u8],
    mut pos: uint,
}

Struct FILERes

pub struct FILERes {
    f: *libc::FILE,
}

Struct FdRes

pub struct FdRes {
    fd: fd_t,
}

Trait Reader

The raw underlying reader trait. All readers must implement this.

Method read

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Read up to len bytes (or EOF) and put them into bytes (which must be at least len bytes long). Return number of bytes read.

Method read_byte

fn read_byte(&self) -> int

Read a single byte, returning a negative value for EOF or read error.

Method eof

fn eof(&self) -> bool

Return whether the stream is currently at EOF position.

Method seek

fn seek(&self, position: int, style: SeekStyle)

Move the current position within the stream. The second parameter determines the position that the first parameter is relative to.

Method tell

fn tell(&self) -> uint

Return the current position within the stream.

Trait ReaderUtil

Generic utility functions defined on readers.

Method read_bytes

fn read_bytes(&self, len: uint) -> ~[u8]

Read len bytes into a new vec.

Method read_until

fn read_until(&self, c: char, include: bool) -> ~str

Read up until a specified character (which is optionally included) or EOF.

Method read_line

fn read_line(&self) -> ~str

Read up until the first '\n' char (which is not returned), or EOF.

Method read_chars

fn read_chars(&self, n: uint) -> ~[char]

Read n utf-8 encoded chars.

Method read_char

fn read_char(&self) -> char

Read a single utf-8 encoded char.

Method read_c_str

fn read_c_str(&self) -> ~str

Read up until the first null byte (which is not returned), or EOF.

Method read_whole_stream

fn read_whole_stream(&self) -> ~[u8]

Read all the data remaining in the stream in one go.

Method each_byte

fn each_byte(&self, it: &fn(int) -> bool)

Iterate over every byte until the iterator breaks or EOF.

Method each_char

fn each_char(&self, it: &fn(char) -> bool)

Iterate over every char until the iterator breaks or EOF.

Method each_line

fn each_line(&self, it: &fn(&str) -> bool)

Iterate over every line until the iterator breaks or EOF.

Method read_lines

fn read_lines(&self) -> ~[~str]

Read all the lines of the file into a vector.

Method read_le_uint_n

fn read_le_uint_n(&self, nbytes: uint) -> u64

Read n (between 1 and 8) little-endian unsigned integer bytes.

Method read_le_int_n

fn read_le_int_n(&self, nbytes: uint) -> i64

Read n (between 1 and 8) little-endian signed integer bytes.

Method read_be_uint_n

fn read_be_uint_n(&self, nbytes: uint) -> u64

Read n (between 1 and 8) big-endian unsigned integer bytes.

Method read_be_int_n

fn read_be_int_n(&self, nbytes: uint) -> i64

Read n (between 1 and 8) big-endian signed integer bytes.

Method read_le_uint

fn read_le_uint(&self) -> uint

Read a little-endian uint (number of bytes depends on system).

Method read_le_int

fn read_le_int(&self) -> int

Read a little-endian int (number of bytes depends on system).

Method read_be_uint

fn read_be_uint(&self) -> uint

Read a big-endian uint (number of bytes depends on system).

Method read_be_int

fn read_be_int(&self) -> int

Read a big-endian int (number of bytes depends on system).

Method read_be_u64

fn read_be_u64(&self) -> u64

Read a big-endian u64 (8 bytes).

Method read_be_u32

fn read_be_u32(&self) -> u32

Read a big-endian u32 (4 bytes).

Method read_be_u16

fn read_be_u16(&self) -> u16

Read a big-endian u16 (2 bytes).

Method read_be_i64

fn read_be_i64(&self) -> i64

Read a big-endian i64 (8 bytes).

Method read_be_i32

fn read_be_i32(&self) -> i32

Read a big-endian i32 (4 bytes).

Method read_be_i16

fn read_be_i16(&self) -> i16

Read a big-endian i16 (2 bytes).

Method read_be_f64

fn read_be_f64(&self) -> f64

Read a big-endian IEEE754 double-precision floating-point (8 bytes).

Method read_be_f32

fn read_be_f32(&self) -> f32

Read a big-endian IEEE754 single-precision floating-point (4 bytes).

Method read_le_u64

fn read_le_u64(&self) -> u64

Read a little-endian u64 (8 bytes).

Method read_le_u32

fn read_le_u32(&self) -> u32

Read a little-endian u32 (4 bytes).

Method read_le_u16

fn read_le_u16(&self) -> u16

Read a little-endian u16 (2 bytes).

Method read_le_i64

fn read_le_i64(&self) -> i64

Read a litle-endian i64 (8 bytes).

Method read_le_i32

fn read_le_i32(&self) -> i32

Read a litle-endian i32 (4 bytes).

Method read_le_i16

fn read_le_i16(&self) -> i16

Read a litle-endian i16 (2 bytes).

Method read_le_f64

fn read_le_f64(&self) -> f64

Read a litten-endian IEEE754 double-precision floating-point (8 bytes).

Method read_le_f32

fn read_le_f32(&self) -> f32

Read a litten-endian IEEE754 single-precision floating-point (4 bytes).

Method read_u8

fn read_u8(&self) -> u8

Read a u8 (1 byte).

Method read_i8

fn read_i8(&self) -> i8

Read a i8 (1 byte).

Trait Writer

The raw underlying writer trait. All writers must implement this.

Method write

fn write(&self, v: &const [u8])

Write all of the given bytes.

Method seek

fn seek(&self, int, SeekStyle)

Move the current position within the stream. The second parameter determines the position that the first parameter is relative to.

Method tell

fn tell(&self) -> uint

Return the current position within the stream.

Method flush

fn flush(&self) -> int

Flush the output buffer for this stream (if there is one).

Method get_type

fn get_type(&self) -> WriterType

Determine if this Writer is writing to a file or not.

Trait WriterUtil

Generic utility functions defined on writers.

Method write_char

fn write_char(&self, ch: char)

Write a single utf-8 encoded char.

Method write_str

fn write_str(&self, s: &str)

Write every char in the given str, encoded as utf-8.

Method write_line

fn write_line(&self, s: &str)

Write the given str, as utf-8, followed by '\n'.

Method write_int

fn write_int(&self, n: int)

Write the result of passing n through int::to_str_bytes.

Method write_uint

fn write_uint(&self, n: uint)

Write the result of passing n through uint::to_str_bytes.

Method write_le_uint

fn write_le_uint(&self, n: uint)

Write a little-endian uint (number of bytes depends on system).

Method write_le_int

fn write_le_int(&self, n: int)

Write a little-endian int (number of bytes depends on system).

Method write_be_uint

fn write_be_uint(&self, n: uint)

Write a big-endian uint (number of bytes depends on system).

Method write_be_int

fn write_be_int(&self, n: int)

Write a big-endian int (number of bytes depends on system).

Method write_be_u64

fn write_be_u64(&self, n: u64)

Write a big-endian u64 (8 bytes).

Method write_be_u32

fn write_be_u32(&self, n: u32)

Write a big-endian u32 (4 bytes).

Method write_be_u16

fn write_be_u16(&self, n: u16)

Write a big-endian u16 (2 bytes).

Method write_be_i64

fn write_be_i64(&self, n: i64)

Write a big-endian i64 (8 bytes).

Method write_be_i32

fn write_be_i32(&self, n: i32)

Write a big-endian i32 (4 bytes).

Method write_be_i16

fn write_be_i16(&self, n: i16)

Write a big-endian i16 (2 bytes).

Method write_be_f64

fn write_be_f64(&self, f: f64)

Write a big-endian IEEE754 double-precision floating-point (8 bytes).

Method write_be_f32

fn write_be_f32(&self, f: f32)

Write a big-endian IEEE754 single-precision floating-point (4 bytes).

Method write_le_u64

fn write_le_u64(&self, n: u64)

Write a little-endian u64 (8 bytes).

Method write_le_u32

fn write_le_u32(&self, n: u32)

Write a little-endian u32 (4 bytes).

Method write_le_u16

fn write_le_u16(&self, n: u16)

Write a little-endian u16 (2 bytes).

Method write_le_i64

fn write_le_i64(&self, n: i64)

Write a little-endian i64 (8 bytes).

Method write_le_i32

fn write_le_i32(&self, n: i32)

Write a little-endian i32 (4 bytes).

Method write_le_i16

fn write_le_i16(&self, n: i16)

Write a little-endian i16 (2 bytes).

Method write_le_f64

fn write_le_f64(&self, f: f64)

Write a little-endian IEEE754 double-precision floating-point (8 bytes).

Method write_le_f32

fn write_le_f32(&self, f: f32)

Write a litten-endian IEEE754 single-precision floating-point (4 bytes).

Method write_u8

fn write_u8(&self, n: u8)

Write a u8 (1 byte).

Method write_i8

fn write_i8(&self, n: i8)

Write a i8 (1 byte).

Implementation of Reader for @Reader

Method read

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Method read_byte

fn read_byte(&self) -> int

Method eof

fn eof(&self) -> bool

Method seek

fn seek(&self, position: int, style: SeekStyle)

Method tell

fn tell(&self) -> uint

Implementation of ReaderUtil for T where <T: Reader>

Method read_bytes

fn read_bytes(&self, len: uint) -> ~[u8]

Method read_until

fn read_until(&self, c: char, include: bool) -> ~str

Method read_line

fn read_line(&self) -> ~str

Method read_chars

fn read_chars(&self, n: uint) -> ~[char]

Method read_char

fn read_char(&self) -> char

Method read_c_str

fn read_c_str(&self) -> ~str

Method read_whole_stream

fn read_whole_stream(&self) -> ~[u8]

Method each_byte

fn each_byte(&self, it: &fn(int) -> bool)

Method each_char

fn each_char(&self, it: &fn(char) -> bool)

Method each_line

fn each_line(&self, it: &fn(s: &str) -> bool)

Method read_lines

fn read_lines(&self) -> ~[~str]

Method read_le_uint_n

fn read_le_uint_n(&self, nbytes: uint) -> u64

Method read_le_int_n

fn read_le_int_n(&self, nbytes: uint) -> i64

Method read_be_uint_n

fn read_be_uint_n(&self, nbytes: uint) -> u64

Method read_be_int_n

fn read_be_int_n(&self, nbytes: uint) -> i64

Method read_le_uint

fn read_le_uint(&self) -> uint

Method read_le_int

fn read_le_int(&self) -> int

Method read_be_uint

fn read_be_uint(&self) -> uint

Method read_be_int

fn read_be_int(&self) -> int

Method read_be_u64

fn read_be_u64(&self) -> u64

Method read_be_u32

fn read_be_u32(&self) -> u32

Method read_be_u16

fn read_be_u16(&self) -> u16

Method read_be_i64

fn read_be_i64(&self) -> i64

Method read_be_i32

fn read_be_i32(&self) -> i32

Method read_be_i16

fn read_be_i16(&self) -> i16

Method read_be_f64

fn read_be_f64(&self) -> f64

Method read_be_f32

fn read_be_f32(&self) -> f32

Method read_le_u64

fn read_le_u64(&self) -> u64

Method read_le_u32

fn read_le_u32(&self) -> u32

Method read_le_u16

fn read_le_u16(&self) -> u16

Method read_le_i64

fn read_le_i64(&self) -> i64

Method read_le_i32

fn read_le_i32(&self) -> i32

Method read_le_i16

fn read_le_i16(&self) -> i16

Method read_le_f64

fn read_le_f64(&self) -> f64

Method read_le_f32

fn read_le_f32(&self) -> f32

Method read_u8

fn read_u8(&self) -> u8

Method read_i8

fn read_i8(&self) -> i8

Implementation of Reader for *libc::FILE

Method read

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Method read_byte

fn read_byte(&self) -> int

Method eof

fn eof(&self) -> bool

Method seek

fn seek(&self, offset: int, whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Implementation of Reader for Wrapper<R, C> where <R: Reader, C>

Method read

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Method read_byte

fn read_byte(&self) -> int

Method eof

fn eof(&self) -> bool

Method seek

fn seek(&self, off: int, whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Implementation of Drop for FILERes

Method finalize

fn finalize(&self)

Implementation of Reader for BytesReader<'self> where <'self>

Method read

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Method read_byte

fn read_byte(&self) -> int

Method eof

fn eof(&self) -> bool

Method seek

fn seek(&self, offset: int, whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Implementation of ::core::cmp::Eq for WriterType

Method eq

fn eq(&self, __other: &WriterType) -> bool

Method ne

fn ne(&self, __other: &WriterType) -> bool

Implementation of Writer for @Writer

Method write

fn write(&self, v: &const [u8])

Method seek

fn seek(&self, a: int, b: SeekStyle)

Method tell

fn tell(&self) -> uint

Method flush

fn flush(&self) -> int

Method get_type

fn get_type(&self) -> WriterType

Implementation of Writer for Wrapper<W, C> where <W: Writer, C>

Method write

fn write(&self, bs: &const [u8])

Method seek

fn seek(&self, off: int, style: SeekStyle)

Method tell

fn tell(&self) -> uint

Method flush

fn flush(&self) -> int

Method get_type

fn get_type(&self) -> WriterType

Implementation of Writer for *libc::FILE

Method write

fn write(&self, v: &const [u8])

Method seek

fn seek(&self, offset: int, whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Method flush

fn flush(&self) -> int

Method get_type

fn get_type(&self) -> WriterType

Implementation of Writer for fd_t

Method write

fn write(&self, v: &const [u8])

Method seek

fn seek(&self, _offset: int, _whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Method flush

fn flush(&self) -> int

Method get_type

fn get_type(&self) -> WriterType

Implementation of Drop for FdRes

Method finalize

fn finalize(&self)

Implementation of WriterUtil for T where <T: Writer>

Method write_char

fn write_char(&self, ch: char)

Method write_str

fn write_str(&self, s: &str)

Method write_line

fn write_line(&self, s: &str)

Method write_int

fn write_int(&self, n: int)

Method write_uint

fn write_uint(&self, n: uint)

Method write_le_uint

fn write_le_uint(&self, n: uint)

Method write_le_int

fn write_le_int(&self, n: int)

Method write_be_uint

fn write_be_uint(&self, n: uint)

Method write_be_int

fn write_be_int(&self, n: int)

Method write_be_u64

fn write_be_u64(&self, n: u64)

Method write_be_u32

fn write_be_u32(&self, n: u32)

Method write_be_u16

fn write_be_u16(&self, n: u16)

Method write_be_i64

fn write_be_i64(&self, n: i64)

Method write_be_i32

fn write_be_i32(&self, n: i32)

Method write_be_i16

fn write_be_i16(&self, n: i16)

Method write_be_f64

fn write_be_f64(&self, f: f64)

Method write_be_f32

fn write_be_f32(&self, f: f32)

Method write_le_u64

fn write_le_u64(&self, n: u64)

Method write_le_u32

fn write_le_u32(&self, n: u32)

Method write_le_u16

fn write_le_u16(&self, n: u16)

Method write_le_i64

fn write_le_i64(&self, n: i64)

Method write_le_i32

fn write_le_i32(&self, n: i32)

Method write_le_i16

fn write_le_i16(&self, n: i16)

Method write_le_f64

fn write_le_f64(&self, f: f64)

Method write_le_f32

fn write_le_f32(&self, f: f32)

Method write_u8

fn write_u8(&self, n: u8)

Method write_i8

fn write_i8(&self, n: i8)

Implementation of Writer for BytesWriter

Method write

fn write(&self, v: &const [u8])

Method seek

fn seek(&self, offset: int, whence: SeekStyle)

Method tell

fn tell(&self) -> uint

Method flush

fn flush(&self) -> int

Method get_type

fn get_type(&self) -> WriterType

Function BytesWriter

fn BytesWriter() -> BytesWriter

Function FILERes

fn FILERes(f: *libc::FILE) -> FILERes

Function FILE_reader

fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader

Function FILE_writer

fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer

Function FdRes

fn FdRes(fd: fd_t) -> FdRes

Function buffered_file_writer

fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str>

Function fd_writer

fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer

Function file_reader

fn file_reader(path: &Path) -> Result<@Reader, ~str>

Function file_writer

fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str>

Function mk_file_writer

fn mk_file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str>

Function print

fn print(s: &str)

Function println

fn println(s: &str)

Function read_whole_file

fn read_whole_file(file: &Path) -> Result<~[u8], ~str>

Function read_whole_file_str

fn read_whole_file_str(file: &Path) -> Result<~str, ~str>

Function seek_in_buf

fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) -> uint

Function stderr

fn stderr() -> @Writer

Function stdin

fn stdin() -> @Reader

Function stdout

fn stdout() -> @Writer

Function u64_from_be_bytes

fn u64_from_be_bytes(data: &const [u8], start: uint, size: uint) -> u64

Function u64_to_be_bytes

fn u64_to_be_bytes<T>(n: u64, size: uint, f: &fn(v: &[u8]) -> T) -> T

Function u64_to_le_bytes

fn u64_to_le_bytes<T>(n: u64, size: uint, f: &fn(v: &[u8]) -> T) -> T

Function with_bytes_reader

fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t

Function with_bytes_writer

fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8]

Function with_str_reader

fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T

Function with_str_writer

fn with_str_writer(f: &fn(@Writer)) -> ~str