Find the size of the file inside a GZIP file

前端 未结 4 914
长情又很酷
长情又很酷 2020-12-06 02:58

Is there a way to find out the size of the original file which is inside a GZIP file in java?

As in, I have a file a.txt of 15 MB which has been GZipped to a.gz of s

4条回答
  •  眼角桃花
    2020-12-06 03:48

    GZIP doesn't let you know about the size of the contents in advance. These are the ways of managing it that I can think of depending on your requirements:

    1. unzip the stream on the fly and either abort if it is too large
    2. unzip the stream but without writing out the content. This will get
    3. the size of the uncompressed data without taking up any space. It only costs the processing to read and inflate
    4. switch to using zip files (which have entries that can tell you the length in advance)
    5. if you know the type of data you are typically receiving, you may be able to statistically estimate the size based on the size of the compressed gzip.

提交回复
热议问题