Compressing v0.1.0

Source
A writer that compresses what is written through it.

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.

Source

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.

NameTypeDescription
allocatorAllocatorwhat the writer's buffers are kept in, about 750 KiB
sinkWriterwhere the compressed stream goes, which the writer takes
formatFormatthe container to write
levelLevelhow hard to compress

Returns: the writer, or fails when the allocator refused

Source

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

Source

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.

NameTypeDescription
byteschar8[..]the data

Returns: how many bytes were taken, which is all of them, or fails after Finish or with the sink's error

Source

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

Source

Destructor

~CompressWriter

func ~CompressWriter(self: &var CompressWriter)

Source