BufWriter
struct BufWriter
BufWriter implements buffering for an io.Write object.
Implementions
Methods
[src]
pub fn new(writer: Write, buf_size: int = 8192): BufWriter {
return BufWriter {
writer,
buf: Bytes.new(len: buf_size),
buffered_: 0,
};
}
Create a new BufWrite with the underlying writer.
[src]
pub fn new(writer: Write, buf_size: int = 8192): BufWriter {
return BufWriter {
writer,
buf: Bytes.new(len: buf_size),
buffered_: 0,
};
}
Create a new BufWrite with the underlying writer.
Create a new BufWrite with the underlying writer.
[src]
pub fn buffered(self): int {
return self.buffered_;
}
Returns the number of bytes that have been written into the current buffer.
[src]
pub fn buffered(self): int {
return self.buffered_;
}
Returns the number of bytes that have been written into the current buffer.
Returns the number of bytes that have been written into the current buffer.
[src]
pub fn available(self): int {
return self.buf.len() - self.buffered_;
}
Returns how many bytes are unused in the buffer.
[src]
pub fn available(self): int {
return self.buf.len() - self.buffered_;
}
Returns how many bytes are unused in the buffer.
Returns how many bytes are unused in the buffer.
available_buffer
pub fn available_buffer(self): Bytes
[src]
pub fn available_buffer(self): Bytes {
return self.buf.slice(self.buffered_, self.buf.len());
}
Returns a slice of the buffer that is available for writing.
available_buffer
pub fn available_buffer(self): Bytes
[src]
pub fn available_buffer(self): Bytes {
return self.buf.slice(self.buffered_, self.buf.len());
}
Returns a slice of the buffer that is available for writing.
Returns a slice of the buffer that is available for writing.
[src]
pub fn write(self, buf: Bytes): int throws IoError {
let offset = 0;
while (buf.len() - offset > self.available()) {
if (self.buffered_ == 0) {
let sz = try self.writer.write(buf.slice(offset, buf.len()));
offset += sz;
} else {
let copy_sz = self.available();
self.buf.copy_from(buf.slice(offset, offset + copy_sz), offset: self.buffered());
self.buffered_ += copy_sz;
offset += copy_sz;
try self.flush();
}
}
self.buf.copy_from(buf.slice(offset, buf.len()), offset: self.buffered_);
self.buffered_ += buf.len() - offset;
return buf.len();
}
[src]
pub fn write(self, buf: Bytes): int throws IoError {
let offset = 0;
while (buf.len() - offset > self.available()) {
if (self.buffered_ == 0) {
let sz = try self.writer.write(buf.slice(offset, buf.len()));
offset += sz;
} else {
let copy_sz = self.available();
self.buf.copy_from(buf.slice(offset, offset + copy_sz), offset: self.buffered());
self.buffered_ += copy_sz;
offset += copy_sz;
try self.flush();
}
}
self.buf.copy_from(buf.slice(offset, buf.len()), offset: self.buffered_);
self.buffered_ += buf.len() - offset;
return buf.len();
}