status = LZ4F_freeDecompressionContext(ctx); if (LZ4F_isError(status))
pg_fatal("could not free LZ4 decompression context: %s",
LZ4F_getErrorName(status));
}
/* Write the header if not yet written. */ if (state->needs_header_flush)
{
cs->writeF(AH, state->buffer, state->compressedlen);
state->needs_header_flush = false;
}
status = LZ4F_compressEnd(state->ctx,
state->buffer, state->buflen,
NULL); if (LZ4F_isError(status))
pg_fatal("could not end compression: %s",
LZ4F_getErrorName(status));
cs->writeF(AH, state->buffer, status);
status = LZ4F_freeCompressionContext(state->ctx); if (LZ4F_isError(status))
pg_fatal("could not end compression: %s",
LZ4F_getErrorName(status));
/* No work needs to be done for a zero-sized output buffer */ if (size <= 0) return0;
/* Verify that there is enough space in the outbuf */ if (size > state->buflen)
{
state->buflen = size;
state->buffer = pg_realloc(state->buffer, size);
}
/* use already decompressed content if available */
dsize = LZ4Stream_read_overflow(state, ptr, size, eol_flag); if (dsize == size || (eol_flag && memchr(ptr, '\n', dsize))) return dsize;
readbuf = pg_malloc(size);
do
{ char *rp; char *rend;
rsize = fread(readbuf, 1, size, state->fp); if (rsize < size && !feof(state->fp))
{
pg_log_error("could not read from input file: %m"); return -1;
}
rp = (char *) readbuf;
rend = (char *) readbuf + rsize;
while (rp < rend)
{
size_t status;
size_t outlen = state->buflen;
size_t read_remain = rend - rp;
memset(state->buffer, 0, outlen);
status = LZ4F_decompress(state->dtx, state->buffer, &outlen,
rp, &read_remain, NULL); if (LZ4F_isError(status))
{
state->errcode = status;
pg_log_error("could not read from input file: %s",
LZ4F_getErrorName(state->errcode)); return -1;
}
/* move what did not fit, if any, at the beginning of the buf */ if (len < outlen)
memmove(state->buffer, state->buffer + len, outlen - len);
outlen -= len;
}
/* if there is available output, save it */ if (outlen > 0)
{ while (state->overflowlen + outlen > state->overflowalloclen)
{
state->overflowalloclen *= 2;
state->overflowbuf = pg_realloc(state->overflowbuf,
state->overflowalloclen);
}
/* Lazy init */ if (!LZ4Stream_init(state, size, true))
pg_fatal("unable to initialize LZ4 library: %s",
LZ4F_getErrorName(state->errcode));
while (remaining > 0)
{ int chunk = Min(remaining, DEFAULT_IO_BUFFER_SIZE);
remaining -= chunk;
status = LZ4F_compressUpdate(state->ctx, state->buffer, state->buflen,
ptr, chunk, NULL); if (LZ4F_isError(status))
pg_fatal("error during writing: %s", LZ4F_getErrorName(status));
if (LZ4Stream_read_internal(state, &c, 1, false) <= 0)
{ if (!LZ4Stream_eof(CFH))
pg_fatal("could not read from input file: %s", LZ4Stream_get_error(CFH)); else
pg_fatal("could not read from input file: end of file");
}
return c;
}
/* *fgets()equivalentimplementationforLZ4compressedfiles.
*/ staticchar *
LZ4Stream_gets(char *ptr, int size, CompressFileHandle *CFH)
{
LZ4State *state = (LZ4State *) CFH->private_data; int ret;
ret = LZ4Stream_read_internal(state, ptr, size - 1, true);
fp = state->fp; if (state->inited)
{ if (state->compressing)
{
status = LZ4F_compressEnd(state->ctx, state->buffer, state->buflen, NULL); if (LZ4F_isError(status))
{
pg_log_error("could not end compression: %s",
LZ4F_getErrorName(status));
success = false;
} else
{
errno = 0; if (fwrite(state->buffer, 1, status, state->fp) != status)
{
errno = (errno) ? errno : ENOSPC;
pg_log_error("could not write to output file: %m");
success = false;
}
}
status = LZ4F_freeCompressionContext(state->ctx); if (LZ4F_isError(status))
{
pg_log_error("could not end compression: %s",
LZ4F_getErrorName(status));
success = false;
}
} else
{
status = LZ4F_freeDecompressionContext(state->dtx); if (LZ4F_isError(status))
{
pg_log_error("could not end decompression: %s",
LZ4F_getErrorName(status));
success = false;
}
pg_free(state->overflowbuf);
}
pg_free(state->buffer);
}
pg_free(state);
CFH->private_data = NULL;
errno = 0;
ret = fclose(fp); if (ret != 0)
{
pg_log_error("could not close file: %m");
success = false;
}
CFH->compression_spec = compression_spec;
state = pg_malloc0(sizeof(*state)); if (CFH->compression_spec.level >= 0)
state->prefs.compressionLevel = CFH->compression_spec.level;
CFH->private_data = state;
} #else/* USE_LZ4 */ void
InitCompressorLZ4(CompressorState *cs, const pg_compress_specification compression_spec)
{
pg_fatal("this build does not support compression with %s", "LZ4");
}
void
InitCompressFileHandleLZ4(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
{
pg_fatal("this build does not support compression with %s", "LZ4");
} #endif/* USE_LZ4 */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-08-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.