/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#ifdef HAVE_LZ4
#include "buffer.h"
#include "istream-private.h"
#include "istream-zlib.h"
#include "iostream-lz4.h"
#include <lz4.h>
struct lz4_istream {
};
bool close_parent)
{
if (close_parent)
}
{
"lz4.read(%s): %s at %"PRIuUOFF_T,
if (zstream->log_errors)
}
{
const unsigned char *data;
int ret;
sizeof(*hdr));
if (ret < 0) {
return ret;
}
return 0;
IOSTREAM_LZ4_MAGIC_LEN) != 0) {
return -1;
}
"lz4 max chunk size too large (%u > %u)",
return -1;
}
return 1;
}
{
const unsigned char *data;
int ret;
if (!zstream->header_read) {
return ret;
}
if (zstream->chunk_left == 0) {
if (ret < 0) {
}
return ret;
}
return 0;
if (zstream->chunk_size == 0 ||
return -1;
}
}
/* read the whole compressed chunk into memory */
while (zstream->chunk_left > 0 &&
}
if (zstream->chunk_left > 0) {
return -1;
}
return ret;
}
/* if we already have max_buffer_size amount of data, fail here */
return -2;
/* allocate enough space for the old data and the new
decompressed chunk. we don't know the original compressed size,
so just allocate the max amount of memory. */
if (ret < 0) {
return -1;
}
return ret;
}
{
}
static void
{
if (v_offset < start_offset) {
/* have to seek backwards */
start_offset = 0;
}
/* seeking backwards within what's already cached */
} else {
/* read and cache forward */
do {
v_offset -
ret = -1;
break;
}
/* some failure, we've broken it */
i_error("lz4_istream.seek(%s) failed: %s",
} else {
/* unexpected EOF. allow it since we may just
want to check if there's anything.. */
}
}
}
if (mark)
}
static int
{
return -1;
}
/* when exact=FALSE always return the parent stat's size, even if we
know the exact value. this is necessary because otherwise e.g. mbox
code can see two different values and think that a compressed mbox
file keeps changing. */
if (!exact)
return 0;
do {
return -1;
}
return 0;
}
{
/* a compressed file doesn't change unexpectedly,
don't clear our caches unnecessarily */
return;
}
}
}
{
i_stream_get_fd(input), 0);
}
#endif