Lzo

Lzo class

Constructors

this
this()

Constructor

Members

Aliases

crc32
alias crc32 = LzoCrc.crc32
Undocumented in source.

Functions

compress
size_t compress(void[] src, void[] dst)

Compresses src data. dst must have a length of at least maxCompressedLength(src.length).

decompressSafe
size_t decompressSafe(void[] src, void[] dst)

Uncompresses src data, checking for dst not to overflow.

uncompress
size_t uncompress(void[] src, void[] dst)

Uncompresses src data. dst must have at least the length of the uncompressed data, which must be memorized at compression time.

Static functions

checkStatus
void checkStatus(LzoStatus status)

Checks if status indicates an error.

maxCompressedLength
size_t maxCompressedLength(size_t uncompressed_length)

Calculates the maximum compressed length of data which has a length of uncompressed_length.

Examples

Simple compress / decompress example.

// LZO instance. (Usually a single one can be shared globally.)
auto lzo = new Lzo;

// Typical function to decompress a buffer that was received over the
// network. (i.e. where the buffer and the expected length of the
// decompressed data are both received from an external source.)
void decompress ( in void[] src, size_t expected_decompressed_length,
    ref void[] dst )
{
    dst.length = expected_decompressed_length;
    assumeSafeAppend(dst);
    auto decompressed_length = lzo.decompressSafe(src, dst);

    // Check that the length of the uncompressed data is what we expected.
    // (It is important to verify this, when the data was received
    // externally.)
    enforce(decompressed_length == expected_decompressed_length);
}

auto original = "compress this!";

// Compress.
auto compressed = new void[lzo.maxCompressedLength(original.length)];
compressed.length = lzo.compress(original, compressed);

// Decompress.
void[] decompressed;
decompress(compressed, original.length, decompressed);

// We should have the original string back now.
test!("==")(decompressed, original);

Meta