is partial gz decompression possible?

前端 未结 3 1245
天涯浪人
天涯浪人 2020-12-31 11:15

For working with images that are stored as .gz files (my image processing software can read .gz files for shorter/smaller disk time/space) I need to check the header of each

3条回答
  •  长发绾君心
    2020-12-31 11:37

    You can use gzip -cd file.gz | dd ibs=1024 count=10 to uncompress just the first 10 KiB, for example.

    gzip -cd decompresses to the standard output.

    Pipe | this into the dd utility.

    The dd utility copies the standard input to the standard output. Sodd ibs=1024 sets the input block size to 1024 bytes instead of the default 512.

    And count=10 Copies only 10 input blocks, thus halting the gzip decompression.

    You'll want to do gzip -cd file.gz | dd count=1 using the standard 512 block size and just ignore the extra 12 bytes.

    A comment highlights that you can use gzip -cd file.gz | head -c $((1024*10)) or in this specific case gzip -cd file.gz | head -c $(512). The comment that the original dd relies on gzip decompressing in 1024 doesn't seem to true. For example dd ibs=2 count=10 decompresses the first 20 bytes.

提交回复
热议问题