raw 'compress', . Pax .
4- - , 4 .
C :
uint8_t *compressBuffer = calloc(bufsize + sizeof (uLongf), 0);
uLongf compressedSize = bufsize;
*((uLongf *)compressBuffer) = filesize;
compress(compressBuffer + sizeof (uLongf), &compressedSize, sourceBuffer, bufsize);
compressBuffer compressizeize size = sizeof (uLongf). , , :
uLongf originalSize = *((uLongf *)compressBuffer);
uint8_t *realCompressBuffer = compressBuffer + sizeof (uLongf);
If you do not trust the client to send the correct size, you will need to perform some verification of the uncompressed data by the size of the server. The suggestion of using uncompress for / dev / null is reasonable.
If you download a .zip file, it contains a directory that indicates the size of the file when it is not compressed. This information is again embedded in the file format, although it depends on malicious clients.
source
share