a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#ifndef IOSTREAM_LZ4_H
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define IOSTREAM_LZ4_H
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/*
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen Dovecot's LZ4 compressed files contain:
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen IOSTREAM_LZ4_HEADER
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen n x (4 byte big-endian: compressed chunk length, compressed chunk)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen*/
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define IOSTREAM_LZ4_MAGIC "Dovecot-LZ4\x0d\x2a\x9b\xc5"
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define IOSTREAM_LZ4_MAGIC_LEN (sizeof(IOSTREAM_LZ4_MAGIC)-1)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstruct iostream_lz4_header {
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen unsigned char magic[IOSTREAM_LZ4_MAGIC_LEN];
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen /* OSTREAM_LZ4_CHUNK_SIZE in big-endian */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen unsigned char max_uncompressed_chunk_size[4];
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen};
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/* How large chunks we're buffering into memory before compressing them */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define OSTREAM_LZ4_CHUNK_SIZE (1024*64)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/* How large chunks we allow in input data before returning a failure.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen This must be at least OSTREAM_LZ4_CHUNK_SIZE, but for future compatibility
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen should be somewhat higher (but not too high to avoid wasting memory for
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen corrupted files). */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define ISTREAM_LZ4_CHUNK_SIZE (1024*1024)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#define IOSTREAM_LZ4_CHUNK_PREFIX_LEN 4 /* big-endian size of chunk */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#endif