Skip to content

Commit

Permalink
tar: Unbreak num parsing and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Oct 19, 2021
1 parent 344f628 commit 49d2e61
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion format/tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func tarDecode(d *decode.D, in interface{}) interface{} {
}
fieldNumStr := func(d *decode.D, name string, nBytes int) uint64 {
return d.FieldUFn(name, func() (uint64, decode.DisplayFormat, string) {
ts := strings.TrimLeft(d.UTF8(nBytes), "0 \x00")
ts := strings.Trim(d.UTF8(nBytes), "0 \x00")
if ts == "" {
return 0, decode.NumberDecimal, ts
}
Expand Down
44 changes: 44 additions & 0 deletions format/tar/testdata/tar.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# echo hello > test
# tar test c > test.tar
$ fq -d tar v /test.tar
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.: {} /test.tar (tar) 0x0-0x27ff.7 (10240)
| | | files: [1] 0x0-0x3ff.7 (1024)
| | | [0]: file {} 0x0-0x3ff.7 (1024)
0x0000|74 65 73 74 00 00 00 00 00 00 00 00 00 00 00 00|test............| name: "test" 0x0-0x63.7 (100)
* |until 0x63.7 (100) | |
0x0060| 30 30 30 36 34 34 20 00 | 000644 . | mode: 644 (420) 0x64-0x6b.7 (8)
0x0060| 30 30 30 37| 0007| uid: 765 (501) 0x6c-0x73.7 (8)
0x0070|36 35 20 00 |65 . |
0x0070| 30 30 30 30 32 34 20 00 | 000024 . | gid: 24 (20) 0x74-0x7b.7 (8)
0x0070| 30 30 30 30| 0000| size: 6 (6) 0x7c-0x87.7 (12)
0x0080|30 30 30 30 30 30 36 20 |0000006 |
0x0080| 31 34 31 33 33 36 32 35| 14133625| mtime: 14133625522 (1634675538) 0x88-0x93.7 (12)
0x0090|35 32 32 20 |522 |
0x0090| 30 31 32 32 32 34 00 20 | 012224. | chksum: 12224 (5268) 0x94-0x9b.7 (8)
0x0090| 30 | 0 | typeflag: "0" 0x9c-0x9c.7 (1)
0x0090| 00 00 00| ...| linkname: "" 0x9d-0x100.7 (100)
0x00a0|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
* |until 0x100.7 (100) | |
0x0100| 75 73 74 61 72 00 | ustar. | magic: "ustar" 0x101-0x106.7 (6)
0x0100| 30 30 | 00 | version: 0 0x107-0x108.7 (2)
0x0100| 77 61 64 65 72 00 00| wader..| uname: "wader" 0x109-0x128.7 (32)
0x0110|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
0x0120|00 00 00 00 00 00 00 00 00 |......... |
0x0120| 73 74 61 66 66 00 00| staff..| gname: "staff" 0x129-0x148.7 (32)
0x0130|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
0x0140|00 00 00 00 00 00 00 00 00 |......... |
0x0140| 30 30 30 30 30 30 20| 000000 | devmajor: 0 0x149-0x150.7 (8)
0x0150|00 |. |
0x0150| 30 30 30 30 30 30 20 00 | 000000 . | devminor: 0 0x151-0x158.7 (8)
0x0150| 00 00 00 00 00 00 00| .......| prefix: "" 0x159-0x1f3.7 (155)
0x0160|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
* |until 0x1f3.7 (155) | |
0x01f0| 00 00 00 00 00 00 00 00 00 00 00 00| ............| header_block_padding: Correct (none) (zero padding) 0x1f4-0x1ff.7 (12)
0x0200|68 65 6c 6c 6f 0a |hello. | data: 68656c6c6f0a 0x200-0x205.7 (6)
0x0200| 00 00 00 00 00 00 00 00 00 00| ..........| data_block_padding: Correct (none) (zero padding) 0x206-0x3ff.7 (506)
0x0210|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................|
* |until 0x3ff.7 (506) | |
0x0400|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................| end_marker: 00000000000000000000000000000000... 0x400-0x7ff.7 (1024)
* |until 0x7ff.7 (1024) | |
0x0800|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................| unknown0: 00000000000000000000000000000000... 0x800-0x27ff.7 (8192)
* |until 0x27ff.7 (end) (8192) | |
Binary file added format/tar/testdata/test.tar
Binary file not shown.

0 comments on commit 49d2e61

Please sign in to comment.