Compressing v0.1.0
CompressWriter
pub struct CompressWriter {
// private fields
}
A writer that compresses what is written to it into another writer, in any of the three formats.
Call Finish when done: it writes the rest of the data and the container's trailer, and nothing written is
complete before it. Flush writes everything so far in a form a decompressor can read up to, without ending the
stream. Not copied.
Associated functions
New
pub func New(
allocator: Allocator,
sink: Writer,
format: Format,
level: Level
) -> CompressWriter ! IoError
A writer that compresses into sink in format, at level.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the writer's buffers are kept in, about 750 KiB |
sink | Writer | where the compressed stream goes, which the writer takes |
format | Format | the container to write |
level | Level | how hard to compress |
Returns: the writer, or fails when the allocator refused
Methods
Finish
pub func Finish(self: &var CompressWriter) -> ! IoError
Compresses everything written so far, writes the end of the stream and the container's trailer, and flushes the sink. Writing after finishing fails; finishing twice does nothing.
Returns: nothing, or fails with the sink's error
Implements Writer
CompressWriter conforms to Writer.
Write
pub func Write(
self: &var CompressWriter,
bytes: char8[..]
) -> uint ! IoError
Takes bytes to compress. They are encoded as enough of them gather, and all of them by Flush or Finish.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the data |
Returns: how many bytes were taken, which is all of them, or fails after Finish or with the sink's error
Flush
pub func Flush(self: &var CompressWriter) -> ! IoError
Encodes everything written so far and ends it with an empty stored block, so a decompressor can read all of it, then flushes the sink. The stream continues afterwards.
Returns: nothing, or fails with the sink's error
Destructor
~CompressWriter
func ~CompressWriter(self: &var CompressWriter)