Read
interface Read
The Read interface usesd to reading bytes from a resource.
Read bytes from the source into the given buffer.
Returns the number of bytes read.
Read bytes from the source into the given buffer. Returns the number of bytes read.
Read bytes from the source into the given buffer. Returns the number of bytes read.
read_to_end
pub fn read_to_end(self, buf: Bytes): int throws IoError
[src]
fn read_to_end(self, buf: Bytes): int throws IoError {
let bytes = Bytes.new(len: 8192);
let total_len = 0;
loop {
let n = try self.read(bytes);
if (n == 0) {
break;
}
total_len += n;
buf.append(bytes.slice(0, n));
}
return total_len;
}
Read all bytes until EOF in this source, placing them into std.io.Bytes
.
read_to_end
pub fn read_to_end(self, buf: Bytes): int throws IoError
[src]
fn read_to_end(self, buf: Bytes): int throws IoError {
let bytes = Bytes.new(len: 8192);
let total_len = 0;
loop {
let n = try self.read(bytes);
if (n == 0) {
break;
}
total_len += n;
buf.append(bytes.slice(0, n));
}
return total_len;
}
Read all bytes until EOF in this source, placing them into std.io.Bytes
.
Read all bytes until EOF in this source, placing them into std.io.Bytes
.
read_to_string
pub fn read_to_string(self): string throws IoError, Utf8Error
[src]
fn read_to_string(self): string throws IoError, Utf8Error {
let buf = Bytes.new();
try self.read_to_end(buf);
return try string.from_utf8(buf);
}
Read all bytes until EOF in this source, returning them as a string.
read_to_string
pub fn read_to_string(self): string throws IoError, Utf8Error
[src]
fn read_to_string(self): string throws IoError, Utf8Error {
let buf = Bytes.new();
try self.read_to_end(buf);
return try string.from_utf8(buf);
}
Read all bytes until EOF in this source, returning them as a string.
Read all bytes until EOF in this source, returning them as a string.
read_exact
pub fn read_exact(self, len: int): Bytes throws IoError
[src]
fn read_exact(self, len: int): Bytes throws IoError {
let bytes = Bytes.new(len: 8192);
let buf = Bytes.new();
let remaining = len;
while (remaining > 0) {
if (remaining < bytes.len()) {
bytes.trunc(remaining);
}
let n = try self.read(bytes);
if (n == 0) {
throw IoError.other("unexpected EOF");
}
buf.append(bytes.slice(0, n));
remaining -= n;
}
return buf;
}
Read the exact number of bytes required.
read_exact
pub fn read_exact(self, len: int): Bytes throws IoError
[src]
fn read_exact(self, len: int): Bytes throws IoError {
let bytes = Bytes.new(len: 8192);
let buf = Bytes.new();
let remaining = len;
while (remaining > 0) {
if (remaining < bytes.len()) {
bytes.trunc(remaining);
}
let n = try self.read(bytes);
if (n == 0) {
throw IoError.other("unexpected EOF");
}
buf.append(bytes.slice(0, n));
remaining -= n;
}
return buf;
}
Read the exact number of bytes required.
Read the exact number of bytes required.
to_read_close
pub fn to_read_close(self, f: |()|): ReadClose
[src]
fn to_read_close(self, f: |() throws IoError|): ReadClose {
return ReadCloseFn { reader: self, close_fn: f };
}
Create a ReadClose
interface from this Read
interface with a close function.
to_read_close
pub fn to_read_close(self, f: |()|): ReadClose
[src]
fn to_read_close(self, f: |() throws IoError|): ReadClose {
return ReadCloseFn { reader: self, close_fn: f };
}
Create a ReadClose
interface from this Read
interface with a close function.
Create a ReadClose
interface from this Read
interface with a close function.
to_nop_read_close
pub fn to_nop_read_close(self): ReadClose
[src]
fn to_nop_read_close(self): ReadClose {
return self.to_read_close(|| {});
}
Returns a ReadClose
with a no-op close
method wrapping this Read
to_nop_read_close
pub fn to_nop_read_close(self): ReadClose
[src]
fn to_nop_read_close(self): ReadClose {
return self.to_read_close(|| {});
}
Returns a ReadClose
with a no-op close
method wrapping this Read
Returns a ReadClose
with a no-op close
method wrapping this Read