
Originally Posted by
Senoble
dnd thank you for your time. If I understand it, I can compress few integers into one 32-bits integer but when I want to write it will be 4 times bigger anyway...
No, you store simply the output BYTE buffer using the compressed length (return value = outlen).
Integer compression example:
Code:
char bytebuf[N], outbuf[N];
FILE *fin = fopen("sample.txt", "rb");
FILE *fout = fopen("sample.txtz", "wb");
n = fread(bytebuf, 1, N, fin);
uint32_t intbuf[N];
for(i=0; i < n; i++) intbuf[i] = bytebuf[i];
int outlen = icompress(intbuf, n, outbuf);
fwrite(outbuf, 1, outlen, fout);
other compression libraries (ex. brotli):
Code:
char bytebuf[N], outbuf[N];
FILE *fin = fopen("sample.txt", "rb");
FILE *fout = fopen("sample.txtz", "wb");
n = fread(bytebuf, 1, N, fin);
int outlen = compress(bytebuf, n, outbuf);
fwrite(outbuf, 1, outlen, fout);
The ouput file length is exactly the compressed length and not 4 times bigger