Нет простого способа получить несжатый размер сжатого файла, если не считать его распаковки и использования функции getfsize (). Это может быть не то, что вы хотите. Я взглянул на RFC 1952 - спецификация формата файла GZIP , и единственное, что могло бы быть полезным, это поле ISIZE, которое содержит "... размер оригинала (без сжатия) входные данные по модулю 2 ^ 32 ".
РЕДАКТИРОВАТЬ:
Я не знаю, помогает ли это, но вот некоторый проверочный код C, который я собрал вместе, который возвращает значение поля ISIZE в файле gzip'd. Это работает для меня, используя Linux и GCC, но ваш пробег может отличаться. Если вы скомпилируете код, а затем передаете имя файла gzip'd в качестве параметра, он сообщит вам несжатый размер исходного файла.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fp = NULL;
int i=0;
if ( argc != 2 ) {
fprintf(stderr, "Must specify file to process.\n" );
return -1;
}
// Open the file for reading
if (( fp = fopen( argv[1], "r" )) == NULL ) {
fprintf( stderr, "Unable to open %s for reading: %s\n", argv[1], strerror(errno));
return -1;
}
// Look at the first two bytes and make sure it's a gzip file
int c1 = fgetc(fp);
int c2 = fgetc(fp);
if ( c1 != 0x1f || c2 != 0x8b ) {
fprintf( stderr, "File is not a gzipped file.\n" );
return -1;
}
// Seek to four bytes from the end of the file
fseek(fp, -4L, SEEK_END);
// Array containing the last four bytes
unsigned char read[4];
for (i=0; i<4; ++i ) {
int charRead = 0;
if ((charRead = fgetc(fp)) == EOF ) {
// This shouldn't happen
fprintf( stderr, "Read end-of-file" );
exit(1);
}
else
read[i] = (unsigned char)charRead;
}
// Copy the last four bytes into an int. This could also be done
// using a union.
int intval = 0;
memcpy( &intval, &read, 4 );
printf( "The uncompressed filesize was %d bytes (0x%02x hex)\n", intval, intval );
fclose(fp);
return 0;
}