Gentoo Archives: gentoo-user

From: Grant Edwards <grant.b.edwards@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: How to copy gzip data from bytestream?
Date: Tue, 22 Feb 2022 14:03:32
Message-Id: sv2qf5$uv1$1@ciao.gmane.io
In Reply to: Re: [gentoo-user] How to copy gzip data from bytestream? by Felix Kuperjans
1 On 2022-02-22, Felix Kuperjans <felix@××××××××××××××.com> wrote:
2
3 > you could use gzip to tell you the compressed size of the file and then
4 > use another method to copy just those bytes (dd for example):
5 >
6 > gzip -clt </dev/sdX
7 >
8 > Should print the compressed size in bytes, although by reading through
9 > the entire stream once.
10
11 That doesn't work. It shows the size of the drive as the
12 "uncompressed" size and 0 as compressed:
13
14 # gzip -clt </dev/sdd
15 compressed uncompressed ratio uncompressed_name
16 31658606592 0 0.0% stdout
17
18 The actual size of the compressed data is about 1/3 the value shown
19 above.
20
21 It's not reading through the stream. It's seeking to the end and
22 looking at what it thinks is the trailer info. I thought that maybe
23 using a pipe instead of a file would make it read through the data,
24 but that doesn't work either:
25
26 $ ls > foo
27 $ ls -l foo
28 -rw-r--r-- 1 grante users 12923 Feb 22 07:51 foo
29
30 $ gzip foo
31 $ ls -l foo.gz
32 -rw-r--r-- 1 grante users 6083 Feb 22 07:51 foo.gz
33
34 $ gzip -clt <foo.gz
35 compressed uncompressed ratio uncompressed_name
36 6083 12923 53.1% stdout
37
38 $ echo asdf >> foo.gz
39
40 $ gzip -clt <foo.gz
41 compressed uncompressed ratio uncompressed_name
42 6088 174482547 100.0% stdout
43
44 $ cat foo.gz | gzip -clt
45 compressed uncompressed ratio uncompressed_name
46 -1 -1 0.0% stdout
47
48
49
50 Here's relevent portion of the strace for the 'gzip -clt <foo.gz'
51 where it seeks to end-8 and reads what it thinks is the uncompressed
52 length and the CRC:
53
54 lseek(0, -8, SEEK_END) = 6080
55 read(0, "2\0\0asdf\n", 8) = 8
56 write(1, " 6088 17"..., 54) = 54
57 close(0) = 0
58 close(1) = 0
59 exit_group(0) = ?

Replies

Subject Author
Re: [gentoo-user] Re: How to copy gzip data from bytestream? Felix Kuperjans <felix@××××××××××××××.com>