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]
fn new(bufreader: R, encoding: &Encoding, trap: DecoderTrap) -> TextReader<R>
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);
fn from_bufreader(bufreader: BufReader<R>,
encoding: &Encoding,
trap: DecoderTrap)
-> TextReader<R>
encoding: &Encoding,
trap: DecoderTrap)
-> TextReader<R>
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);
fn get_bufreader(&self) -> &BufReader<R>
Gets a reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.
fn get_bufreader_mut(&mut self) -> &BufReader<R>
Gets a mutable reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.
fn into_bufreader(self) -> BufReader<R>
Unwraps this TextReader
, returning the underlying reader.
Note that any leftover data in the internal chunk is lost.
fn get_decoder(&self) -> &RawDecoder
Gets a reference to the underlying decoder.
fn get_decoder_mut(&mut self) -> &mut RawDecoder
Gets a mutable reference to the underlying decoder.
fn into_decoder(self) -> Box<RawDecoder>
Unwraps this TextReader
, returning the underlying decoder.
fn read_to_end(&mut self, buf: &mut String) -> Result<usize>
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)?;
fn read_line(&mut self, buf: &mut String) -> Result<usize>
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)?;
fn lines(self) -> Lines<R>
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.