BufReader
struct BufReader
BufRead implements buffering for an io.Read object.
[src]
pub fn new(reader: Read, buf_size: int = 8192): BufReader {
return BufReader {
reader,
buf: Bytes.new(len: buf_size),
offset: 0,
remaining: 0,
};
}
Create a new BufRead with the underlying reader.
[src]
pub fn new(reader: Read, buf_size: int = 8192): BufReader {
return BufReader {
reader,
buf: Bytes.new(len: buf_size),
offset: 0,
remaining: 0,
};
}
Create a new BufRead with the underlying reader.
Create a new BufRead with the underlying reader.
[src]
pub fn fill_buf(self): Bytes throws IoError {
if (self.remaining == 0) {
let sz = try self.reader.read(self.buf);
self.offset = 0;
self.remaining = sz;
}
return self.buf.slice(self.offset, self.offset + self.remaining);
}
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
[src]
pub fn fill_buf(self): Bytes throws IoError {
if (self.remaining == 0) {
let sz = try self.reader.read(self.buf);
self.offset = 0;
self.remaining = sz;
}
return self.buf.slice(self.offset, self.offset + self.remaining);
}
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
[src]
pub fn consume(self, len: int) {
self.offset += len;
self.remaining -= len;
if (self.remaining < 0) {
self.remaining = 0;
}
}
Tells this buffer that len
bytes have been consumed from the buffer, so they should no longer be returned in calls to read.
[src]
pub fn consume(self, len: int) {
self.offset += len;
self.remaining -= len;
if (self.remaining < 0) {
self.remaining = 0;
}
}
Tells this buffer that len
bytes have been consumed from the buffer, so they should no longer be returned in calls to read.
Tells this buffer that len
bytes have been consumed from the buffer, so they should no longer be returned in calls to read.
read_until
pub fn read_until(self, delim: int, buf: Bytes): int throws IoError
[src]
pub fn read_until(self, delim: int, buf: Bytes): int throws IoError {
let sz = 0;
loop {
let data = try self.fill_buf();
if (data.is_empty()) {
break;
}
if (let idx = data.find(delim)) {
buf.append(data.slice(0, idx + 1));
self.consume(idx + 1);
sz += idx + 1;
break;
} else {
buf.append(data);
self.consume(data.len());
}
}
return sz;
}
Read all bytes into buf
until the delimiter delim
or EOF is reached.
read_until
pub fn read_until(self, delim: int, buf: Bytes): int throws IoError
[src]
pub fn read_until(self, delim: int, buf: Bytes): int throws IoError {
let sz = 0;
loop {
let data = try self.fill_buf();
if (data.is_empty()) {
break;
}
if (let idx = data.find(delim)) {
buf.append(data.slice(0, idx + 1));
self.consume(idx + 1);
sz += idx + 1;
break;
} else {
buf.append(data);
self.consume(data.len());
}
}
return sz;
}
Read all bytes into buf
until the delimiter delim
or EOF is reached.
Read all bytes into buf
until the delimiter delim
or EOF is reached.
[src]
pub fn read_line(self): string throws IoError, Utf8Error {
let buf = Bytes.new();
try self.read_until(0xa, buf);
return try string.from_utf8(buf);
}
Read all bytes until a newline (the 0xA byte) is reached.
[src]
pub fn read_line(self): string throws IoError, Utf8Error {
let buf = Bytes.new();
try self.read_until(0xa, buf);
return try string.from_utf8(buf);
}
Read all bytes until a newline (the 0xA byte) is reached.
Read all bytes until a newline (the 0xA byte) is reached.
skip_until
pub fn skip_until(self, delim: int): int throws IoError
[src]
pub fn skip_until(self, delim: int): int throws IoError {
let sz = 0;
loop {
let data = try self.fill_buf();
if (data.is_empty()) {
break;
}
if (let idx = data.find(delim)) {
sz += idx + 1;
self.consume(idx + 1);
break;
} else {
sz += data.len();
self.consume(data.len());
}
}
return sz;
}
Skip all bytes until the delimiter delim
or EOF is reached.
skip_until
pub fn skip_until(self, delim: int): int throws IoError
[src]
pub fn skip_until(self, delim: int): int throws IoError {
let sz = 0;
loop {
let data = try self.fill_buf();
if (data.is_empty()) {
break;
}
if (let idx = data.find(delim)) {
sz += idx + 1;
self.consume(idx + 1);
break;
} else {
sz += data.len();
self.consume(data.len());
}
}
return sz;
}
Skip all bytes until the delimiter delim
or EOF is reached.
Skip all bytes until the delimiter delim
or EOF is reached.
[src]
pub fn read(self, buf: Bytes): int throws IoError {
if (self.remaining == 0 && buf.len() >= self.buf.len()) {
return try self.reader.read(buf);
}
let data = try self.fill_buf();
let sz = data.len().min(buf.len());
buf.copy_from(data.slice(0, sz));
self.consume(sz);
return sz;
}
[src]
pub fn read(self, buf: Bytes): int throws IoError {
if (self.remaining == 0 && buf.len() >= self.buf.len()) {
return try self.reader.read(buf);
}
let data = try self.fill_buf();
let sz = data.len().min(buf.len());
buf.copy_from(data.slice(0, sz));
self.consume(sz);
return sz;
}