3

I know that zlib/miniz provides compressBound which returns a upper bound of deflate/compress size, according to plain-text size. That's convenient.

Is there a function for inflate (zlib/miniz) which return upper bound of inflate/decompress size? Or a simple formula determines it? like:

decompress size = compressed size * factor
Panup Pong
  • 1,871
  • 2
  • 22
  • 44
junfx
  • 123
  • 8

1 Answers1

6

Yes, but I don't think you will find it very useful. The upper limit is 1032 times the size of the input data.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • and the fact is that one can not tell the number by scanning the compressed data? – junfx Nov 14 '14 at 08:17
  • 2
    You can determine the uncompressed data size by reading and decoding all of the compressed data without actually writing the uncompressed data, and adding up how many bytes would have been written. That is not an upper bound, but rather the exact size. – Mark Adler Nov 14 '14 at 15:24
  • @MarkAdler Can it be done without allocating any memory beforehand? I tried doing `uncompress(NULL, &dsize, cbuf, csize);`, but that doesn't seem to work. – user966939 Jun 03 '19 at 19:28
  • @user966939 No, `uncompress()` does not support that. However it would be straightforward for you to decompress and discard data using the `inflate*` functions, in order to find the length of the uncompressed data. It would be faster though to only decompress once. You can use `realloc()` or other growable data structures to increase the size of the allocated memory as needed, – Mark Adler Jun 03 '19 at 19:51