3
#include "DeflateEncoder.h"
4
#include "DeflateDecoder.h"
8
bool compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw ()
11
NDeflate::NEncoder::CCoder cc;
13
if (cc.SetEncoderNumPasses(num_passes) != S_OK)
16
if (cc.SetEncoderNumFastBytes(num_fast_bytes) != S_OK)
19
ISequentialInStream in(reinterpret_cast<const char*>(in_data), in_size);
20
ISequentialOutStream out(reinterpret_cast<char*>(out_data), out_size);
22
UINT64 in_size_l = in_size;
24
if (cc.Code(&in, &out, &in_size_l) != S_OK)
27
out_size = out.size_get();
29
if (out.overflow_get())
38
bool decompress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned out_size) throw () {
40
NDeflate::NDecoder::CCoder cc;
42
ISequentialInStream in(reinterpret_cast<const char*>(in_data), in_size);
43
ISequentialOutStream out(reinterpret_cast<char*>(out_data), out_size);
45
UINT64 in_size_l = in_size;
46
UINT64 out_size_l = out_size;
48
if (cc.Code(&in, &out, &in_size_l, &out_size_l) != S_OK)
51
if (out.size_get() != out_size || out.overflow_get())
60
bool compress_rfc1950_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw ()
67
// 3 - max compression
68
unsigned header = (8 << 8) | (7 << 12) | (3 << 6);
70
header += 31 - (header % 31);
72
out_data[0] = (header >> 8) & 0xFF;
73
out_data[1] = header & 0xFF;
76
unsigned size = out_size - 6;
77
if (!compress_deflate_7z(in_data, in_size, out_data, size, num_passes, num_fast_bytes)) {
82
unsigned adler = adler32(adler32(0,0,0), in_data, in_size);
84
out_data[0] = (adler >> 24) & 0xFF;
85
out_data[1] = (adler >> 16) & 0xFF;
86
out_data[2] = (adler >> 8) & 0xFF;
87
out_data[3] = adler & 0xFF;