ostream-lz4.c revision 8109f3187f5ece5565de1813209af42dc7bb768b
/* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#ifdef HAVE_LZ4
#include "ostream-private.h"
#include "ostream-zlib.h"
#include "iostream-lz4.h"
#include <lz4.h>
#define CHUNK_SIZE OSTREAM_LZ4_CHUNK_SIZE
struct lz4_ostream {
struct ostream_private ostream;
unsigned char compressbuf[CHUNK_SIZE];
unsigned int compressbuf_offset;
/* chunk size, followed by compressed data */
unsigned char outbuf[IOSTREAM_LZ4_CHUNK_PREFIX_LEN +
unsigned int outbuf_offset, outbuf_used;
};
bool close_parent)
{
if (close_parent)
}
{
if (zstream->outbuf_used == 0)
return 1;
if (ret < 0) {
return -1;
}
return 0;
}
zstream->outbuf_offset = 0;
zstream->outbuf_used = 0;
return 1;
}
{
int ret;
if (zstream->compressbuf_offset == 0)
return 1;
return ret;
#if defined(HAVE_LZ4_COMPRESS_DEFAULT)
i_assert(max_dest_size >= 0);
if (max_dest_size == 0) {
"lz4-compress: input size %u too large (> %u)",
return -1;
}
#else
#endif /* defined(HAVE_LZ4_COMPRESS_DEFAULT) */
zstream->compressbuf_offset = 0;
return 1;
}
static ssize_t
{
ssize_t added_bytes = 0;
int ret;
do {
added_bytes += max_size;
if (ret <= 0)
}
} while (size > 0);
return added_bytes;
}
{
if (o_stream_lz4_compress(zstream) < 0)
return -1;
if (o_stream_lz4_send_outbuf(zstream) < 0)
return -1;
return o_stream_flush_parent(stream);
}
static ssize_t
{
unsigned int i;
/* error / we still couldn't flush existing data to
parent stream. */
return ret;
}
for (i = 0; i < iov_count; i++) {
if (ret < 0)
return -1;
break;
}
return bytes;
}
{
struct iostream_lz4_header *hdr;
struct lz4_ostream *zstream;
(OSTREAM_LZ4_CHUNK_SIZE & 0x000000ff);
}
#endif