Struct textstream::TextReader [] [src]

pub struct TextReader<R: Read> { /* fields omitted */ }

The TextReader struct is wrapper for BufReader to decode text codecs.

Methods

impl<R: Read> TextReader<R>
[src]

Creates a new TextReader with codec.

Examples

extern crate textstream;
extern crate encoding;
use std::fs::File;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = File::open("shiftjis.txt")?;
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);

Creates a new TextReader from BufReader.

Examples

extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);

Gets a reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.

Gets a mutable reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.

Unwraps this TextReader, returning the underlying reader. Note that any leftover data in the internal chunk is lost.

Gets a reference to the underlying decoder.

Gets a mutable reference to the underlying decoder.

Unwraps this TextReader, returning the underlying decoder.

Read decoded text until file end, placing them into buf. If successful, this function will return the total number of bytes read.

Examples:

extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use textstream::TextReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
let mut s = String::new();
reader.read_to_end(&mut s)?;

Read decoded text until file end, placing them into buf. If successful, this function will return the total number of bytes read.

Examples:

extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
let mut s = String::new();
reader.read_line(&mut s)?;

Returns an iterator over the lines of this reader. The iterator returned from this function will yield instances of textstream::Result<String>. Each string will not have a newline byte (the 0xA byte) or CRLF (0xD, 0xA bytes) at the end.