Use hd consistently, not xxd, in docs

This commit is contained in:
Nigel Tao committed 2022-04-30 13:20:08 +10:00
1 parent 7eaf488bae
commit e9cb3c8b34
3 files changed
+32 -26

No files matched your search

+5 -4
View File
@@ -51,10 +51,11 @@ uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE];
// src_ptr and src_len hold a gzip-encoded "Hello Wuffs."
//
// $ echo "Hello Wuffs." | gzip --no-name | xxd
// 00000000: 1f8b 0800 0000 0000 0003 f348 cdc9 c957 ...........H...W
// 00000010: 082f 4d4b 2bd6 e302 003c 8475 bb0d 0000 ./MK+....<.u....
// 00000020: 00 .
// $ echo "Hello Wuffs." | gzip --no-name | hd
// 00000000 1f 8b 08 00 00 00 00 00 00 03 f3 48 cd c9 c9 57 |...........H...W|
// 00000010 08 2f 4d 4b 2b d6 e3 02 00 3c 84 75 bb 0d 00 00 |./MK+....<.u....|
// 00000020 00 |.|
// 00000021
//
// Passing --no-name to the gzip command line also means to skip the timestamp,
// which means that its output is deterministic.
+3 -2
View File
@@ -143,8 +143,9 @@ The final line says that the CRC-32 checksum of "Hi\n" is `0xD522_3C9A`. This
can be verified by running the `/usr/bin/crc32` program:
```
$ echo Hi | xxd /dev/stdin
00000000: 4869 0a Hi.
$ echo Hi | hd /dev/stdin
00000000 48 69 0a |Hi.|
00000003
$ echo Hi | crc32 /dev/stdin
d5223c9a
```
+24 -20
View File
@@ -23,21 +23,23 @@ other formats are TODO.
For example, look at `test/data/romeo.txt*`. First, the uncompressed text:
$ xxd test/data/romeo.txt
00000000: 526f 6d65 6f20 616e 6420 4a75 6c69 6574 Romeo and Juliet
00000010: 0a45 7863 6572 7074 2066 726f 6d20 4163 .Excerpt from Ac
$ hd test/data/romeo.txt
00000000 52 6f 6d 65 6f 20 61 6e 64 20 4a 75 6c 69 65 74 |Romeo and Juliet|
00000010 0a 45 78 63 65 72 70 74 20 66 72 6f 6d 20 41 63 |.Excerpt from Ac|
etc
00000390: 740a 536f 2073 7475 6d62 6c65 7374 206f t.So stumblest o
000003a0: 6e20 6d79 2063 6f75 6e73 656c 3f0a n my counsel?.
00000390 74 0a 53 6f 20 73 74 75 6d 62 6c 65 73 74 20 6f |t.So stumblest o|
000003a0 6e 20 6d 79 20 63 6f 75 6e 73 65 6c 3f 0a |n my counsel?.|
000003ae
The raw deflate encoding:
$ xxd test/data/romeo.txt.deflate
00000000: 4d53 c16e db30 0cbd f32b d853 2e46 0e3d MS.n.0...+.S.F.=
00000010: 2e87 20ed 0234 c5ba 0049 861e 861d 149b .. ..4...I......
$ hd test/data/romeo.txt.deflate
00000000 4d 53 c1 6e db 30 0c bd f3 2b d8 53 2e 46 0e 3d |MS.n.0...+.S.F.=|
00000010 2e 87 20 ed 02 34 c5 ba 00 49 86 1e 86 1d 14 9b |.. ..4...I......|
etc
00000200: 7d13 8ffd b9a3 24bb 68f4 eb30 7a59 610d }.....$.h..0zYa.
00000210: 7f01 ..
00000200 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 7a 59 61 0d |}.....$.h..0zYa.|
00000210 7f 01 |..|
00000212
The gzip format wraps a variable length header (in this case, 20 bytes) and 8
byte footer around the raw deflate data. The header contains the NUL-terminated
@@ -45,23 +47,25 @@ C string name of the original, uncompressed file, "romeo.txt", amongst other
data. The footer contains a 4 byte CRC32 checksum and a 4 byte length of the
uncompressed file (0x3ae = 942 bytes).
$ xxd test/data/romeo.txt.gz
00000000: 1f8b 0808 26d8 5d59 0003 726f 6d65 6f2e ....&.]Y..romeo.
00000010: 7478 7400 4d53 c16e db30 0cbd f32b d853 txt.MS.n.0...+.S
$ hd test/data/romeo.txt.gz
00000000 1f 8b 08 08 26 d8 5d 59 00 03 72 6f 6d 65 6f 2e |....&.]Y..romeo.|
00000010 74 78 74 00 4d 53 c1 6e db 30 0c bd f3 2b d8 53 |txt.MS.n.0...+.S|
etc
00000210: de5d 2c67 7d13 8ffd b9a3 24bb 68f4 eb30 .],g}.....$.h..0
00000220: 7a59 610d 7f01 ef07 e5ab ae03 0000 zYa...........
00000210 de 5d 2c 67 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 |.],g}.....$.h..0|
00000220 7a 59 61 0d 7f 01 ef 07 e5 ab ae 03 00 00 |zYa...........|
0000022e
The zlib format wraps a 2 byte header and 4 byte footer around the raw deflate
data. The footer contains a 4 byte Adler32 checksum. TODO: move this to
std/zlib/README.md.
$ xxd test/data/romeo.txt.zlib
00000000: 789c 4d53 c16e db30 0cbd f32b d853 2e46 x.MS.n.0...+.S.F
00000010: 0e3d 2e87 20ed 0234 c5ba 0049 861e 861d .=.. ..4...I....
$ hd test/data/romeo.txt.zlib
00000000 78 9c 4d 53 c1 6e db 30 0c bd f3 2b d8 53 2e 46 |x.MS.n.0...+.S.F|
00000010 0e 3d 2e 87 20 ed 02 34 c5 ba 00 49 86 1e 86 1d |.=.. ..4...I....|
etc
00000200: 2c67 7d13 8ffd b9a3 24bb 68f4 eb30 7a59 ,g}.....$.h..0zY
00000210: 610d 7f01 57bb 3ede a...W.>.
00000200 2c 67 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 7a 59 |,g}.....$.h..0zY|
00000210 61 0d 7f 01 57 bb 3e de |a...W.>.|
00000218
# Wire Format Worked Example