10#include "RConfigure.h"
31static void R__zipOld(
int cxlevel,
int *srcsize,
const char *src,
int *tgtsize,
char *tgrt,
int *irep);
32static void R__zipZLIB(
int cxlevel,
int *srcsize,
const char *src,
int *tgtsize,
char *tgrt,
int *irep);
33static void R__unzipZLIB(
int *srcsize,
const unsigned char *src,
int *tgtsize,
unsigned char *tgt,
int *irep);
61unsigned long R__crc32(
unsigned long crc,
const unsigned char* buf,
unsigned int len)
63 return crc32(crc, buf, len);
79 if (*srcsize < 1 +
HDRSIZE + 1) {
97 R__zipLZMA(cxlevel, srcsize, src, tgtsize, tgt, irep);
99 R__zipLZ4(cxlevel, srcsize, src, tgtsize, tgt, irep);
101 R__zipZSTD(cxlevel, srcsize, src, tgtsize, tgt, irep);
103 R__zipOld(cxlevel, srcsize, src, tgtsize, tgt, irep);
108 R__zipZLIB(cxlevel, srcsize, src, tgtsize, tgt, irep);
115static void R__zipOld(
int cxlevel,
int *srcsize,
const char *src,
int *tgtsize,
char *tgt,
int *irep)
117 int method = Z_DEFLATED;
121 if (cxlevel > 9) cxlevel = 9;
127 R__error(
"target buffer too small");
130 if (*srcsize > 0xffffff) {
141 state.
in_size = (unsigned) (*srcsize);
145 state.
out_size = (unsigned) (*tgtsize);
158 tgt[2] = (char) method;
161 tgt[3] = (char)(state.
out_size & 0xff);
162 tgt[4] = (char)((state.
out_size >> 8) & 0xff);
163 tgt[5] = (char)((state.
out_size >> 16) & 0xff);
165 tgt[6] = (char)(state.
in_size & 0xff);
166 tgt[7] = (char)((state.
in_size >> 8) & 0xff);
167 tgt[8] = (char)((state.
in_size >> 16) & 0xff);
176static void R__zipZLIB(
int cxlevel,
int *srcsize,
const char *src,
int *tgtsize,
char *tgt,
int *irep)
179 int method = Z_DEFLATED;
183 unsigned l_in_size, l_out_size;
187 R__error(
"target buffer too small");
190 if (*srcsize > 0xffffff) {
195 stream.next_in = (Bytef*)src;
196 stream.avail_in = (uInt)(*srcsize);
198 stream.next_out = (Bytef*)(&tgt[
HDRSIZE]);
199 stream.avail_out = (uInt)(*tgtsize) -
HDRSIZE;
201 stream.zalloc =
nullptr;
202 stream.zfree =
nullptr;
203 stream.opaque =
nullptr;
205 if (cxlevel > 9) cxlevel = 9;
206 err = deflateInit(&stream, cxlevel);
208 printf(
"error %d in deflateInit (zlib)\n",
err);
212 while ((
err = deflate(&stream, Z_FINISH)) != Z_STREAM_END) {
219 err = deflateEnd(&stream);
221 printf(
"error %d in deflateEnd (zlib)\n",
err);
225 tgt[2] = (char) method;
227 l_in_size = (unsigned) (*srcsize);
228 l_out_size = stream.total_out;
229 tgt[3] = (char)(l_out_size & 0xff);
230 tgt[4] = (char)((l_out_size >> 8) & 0xff);
231 tgt[5] = (char)((l_out_size >> 16) & 0xff);
233 tgt[6] = (char)(l_in_size & 0xff);
234 tgt[7] = (char)((l_in_size >> 8) & 0xff);
235 tgt[8] = (char)((l_in_size >> 16) & 0xff);
237 *irep = stream.total_out +
HDRSIZE;
246 return src[0] ==
'Z' && src[1] ==
'L' && src[2] == Z_DEFLATED;
251 return src[0] ==
'C' && src[1] ==
'S' && src[2] == Z_DEFLATED;
256 return src[0] ==
'X' && src[1] ==
'Z' && src[2] == 0;
261 return src[0] ==
'L' && src[1] ==
'4';
266 return src[0] ==
'Z' && src[1] ==
'S' && src[2] ==
'\1';
304 fprintf(stderr,
"Error R__unzip_header: error in header. Values: %x%x\n", src[0], src[1]);
308 *srcsize =
HDRSIZE + ((long)src[3] | ((long)src[4] << 8) | ((long)src[5] << 16));
309 *tgtsize = (long)src[6] | ((
long)src[7] << 8) | ((long)src[8] << 16);
339 long ibufcnt, obufcnt;
346 fprintf(stderr,
"R__unzip: too small source\n");
352 fprintf(stderr,
"Error R__unzip: error in header\n");
357 ibufcnt = (long)src[3] | ((
long)src[4] << 8) | ((long)src[5] << 16);
358 isize = (long)src[6] | ((
long)src[7] << 8) | ((long)src[8] << 16);
362 if (obufcnt < isize) {
363 fprintf(stderr,
"R__unzip: too small target (needed: %ld, given: %ld)\n", isize, obufcnt);
367 if (ibufcnt +
HDRSIZE != *srcsize) {
368 fprintf(stderr,
"R__unzip: discrepancy in source length (expected size: %d, real size: %ld)\n",
378 R__unzipLZMA(srcsize, src, tgtsize, tgt, irep);
389 if (
R__Inflate(&ibufptr, &ibufcnt, &obufptr, &obufcnt)) {
390 fprintf(stderr,
"R__unzip: error during decompression\n");
396 if (obufptr - tgt > *tgtsize) {
397 fprintf(stderr,
"R__unzip: discrepancy (%ld) with initial size: %ld, tgtsize=%d\n", (
long)(obufptr - tgt), isize,
399 *irep = obufptr - tgt;
406void R__unzipZLIB(
int *srcsize,
const unsigned char *src,
int *tgtsize,
unsigned char *tgt,
int *irep)
411 stream.next_in = (Bytef *)(&src[
HDRSIZE]);
412 stream.avail_in = (uInt)(*srcsize) -
HDRSIZE;
413 stream.next_out = (Bytef *)tgt;
414 stream.avail_out = (uInt)(*tgtsize);
415 stream.zalloc =
nullptr;
416 stream.zfree =
nullptr;
417 stream.opaque =
nullptr;
419 err = inflateInit(&stream);
421 fprintf(stderr,
"R__unzip: error %d in inflateInit (zlib)\n",
err);
425 while ((
err = inflate(&stream, Z_FINISH)) != Z_STREAM_END) {
428 fprintf(stderr,
"R__unzip: error %d in inflate (zlib)\n",
err);
435 *irep = stream.total_out;
int R__bi_init(bits_internal_state *state)
int gCompressionLevel
Copyright (C) 1990-1993 Mark Adler, Richard B.
static int is_valid_header(unsigned char *src)
static int is_valid_header_zlib(unsigned char *src)
Below are the routines for unzipping (inflating) buffers.
static int is_valid_header_lz4(unsigned char *src)
static int is_valid_header_old(unsigned char *src)
int R__unzip(int *srcsize, uch *src, int *tgtsize, uch *tgt, int *irep)
static int is_valid_header_lzma(unsigned char *src)
static int R__unzipZLIB(int *srcsize, unsigned char *src, int *tgtsize, unsigned char *tgt, int *irep)
ROOT::RCompressionSetting::EAlgorithm::EValues R__getCompressionAlgorithm(unsigned char *buf, size_t bufsize)
ROOT::RCompressionSetting::EAlgorithm::EValues R__ZipMode
int R__SetZipMode(ROOT::RCompressionSetting::EAlgorithm::EValues mode)
static int R__zipOld(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgrt, int *irep)
Forward decl's.
unsigned long R__crc32(unsigned long crc, unsigned char *buf, unsigned int len)
static int R__zipZLIB(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgrt, int *irep)
Compress buffer contents using the venerable zlib algorithm.
int R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, ROOT::RCompressionSetting::EAlgorithm::EValues compressionAlgorithm)
static int is_valid_header_zstd(unsigned char *src)
int R__unzip_header(int *srcsize, uch *src, int *tgtsize)
tree_internal_state * R__get_thread_tree_state()
void R__unzipLZ4(int *srcsize, const unsigned char *src, int *tgtsize, unsigned char *tgt, int *irep)
void R__zipLZ4(int cxlevel, int *srcsize, const char *src, int *tgtsize, char *tgt, int *irep)
void R__zipZSTD(int cxlevel, int *srcsize, const char *src, int *tgtsize, char *tgt, int *irep)
void R__unzipZSTD(int *srcsize, const unsigned char *src, int *tgtsize, unsigned char *tgt, int *irep)
printf("Client 0: bytes recv = %d, bytes sent = %d\n", s0->GetBytesRecv(), s0->GetBytesSent())
EValues
Note: this is only temporarily a struct and will become a enum class hence the name convention used.
@ kUseGlobal
Use the global compression algorithm.
@ kLZ4
Use LZ4 compression.
@ kOldCompressionAlgo
Use the old compression algorithm.
@ kZSTD
Use ZSTD compression.
@ kUndefined
Undefined compression algorithm (must be kept the last of the list in case a new algorithm is added).
@ kZLIB
Use ZLIB compression.
@ kLZMA
Use LZMA compression.
tree_internal_state * t_state
uch R__window[2L *((unsigned) 32768)]
Pos R__prev[((unsigned) 32768)]