Skip to content

Commit

Permalink
readme: Nicer demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Oct 10, 2021
1 parent 0af4c2b commit 4cee498
Show file tree
Hide file tree
Showing 4 changed files with 1,215 additions and 41 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ cover: test
cat cover.out.html | grep '<option value="file' | sed -E 's/.*>(.*) \((.*)%\)<.*/\2 \1/' | sort -rn

.PHONY: doc
doc: fq doc/file.mp3 doc/file.mp4 doc/formats.svg
doc: fq doc/file.mp3 doc/file.mp4 doc/formats.svg doc/demo.svg
@doc/mdsh.sh ./fq *.md doc/*.md

.PHONY: doc/demo.svg
doc/demo.svg: fq
(cd doc ; ./demo.sh ../fq) | go run github.com/wader/ansisvg@master > doc/demo.svg

.PHONY: doc/formats.svg
doc/formats.svg: fq
./fq -rnf doc/formats_diagram.jq | dot -Tsvg -o doc/formats.svg
Expand Down
41 changes: 1 addition & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,7 @@

Tool, language and format decoders for exploring binary data.

<sub>
<pre sh>
<b># Overview of mp3 file</b
$ fq . file.mp3 
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.: {} file.mp3 (mp3)
0x000|49 44 33 04 00 00 00 00 15 39 54 53 53 45 00 00|ID3......9TSSE..| headers: [1]
* |until 0xac2.7 (2755) | |
0xac0| ff fb 40 c0 00 00 00 00 00 00 00 00 00| ..@..........| frames: [3]
0xad0|00 00 00 00 00 00 00 00 49 6e 66 6f 00 00 00 0f|........Info....|
* |until 0xd19.7 (end) (599) | |
| | | footers: [0]

<b># Show ID3v2 tag in mp3 file</b
$ fq '.headers[0]' file.mp3 
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.headers[0]: {} (id3v2)
0x000|49 44 33 |ID3 | magic: "ID3" (Correct)
0x000| 04 | . | version: 4
0x000| 00 | . | revision: 0
0x000| 00 | . | flags: {}
0x000| 00 00 15 39 | ...9 | size: 2745
0x000| 54 53 53 45 00 00| TSSE..| frames: [2]
0x010|00 0f 00 00 03 4c 61 76 66 35 38 2e 37 36 2e 31|.....Lavf58.76.1|
* |until 0xab8.7 (2735) | |
0xab0| 00 00 00 00 00 00 00| .......| padding: Correct (none) (zero padding)
0xac0|00 00 00 |... |

<b># Resolution of ID3v2 cover art</b
$ fq '.headers[0].frames[] | select(.id == "APIC").picture.chunks[] | select(.type == "IHDR") | {width, height}' file.mp3 
{
"height": 240,
"width": 320
}

<b># Extract image file</b
$ fq '.headers[].frames[] | select(.id == "APIC")?.picture | tobits' file.mp3 > file.png 
$ file file.png 
file.png: PNG image data, 320 x 240, 8-bit/color RGB, non-interlaced

</pre>
</sub>
![fq demo](doc/demo.svg)

## Goals

Expand Down
26 changes: 26 additions & 0 deletions doc/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

FQ="$1"

c() {
echo -e "\x1b[97m# $1\x1b[0m"
}

s() {
echo "\$ $1"
sh -c "${1/fq/$FQ -C}"
}

c "Overview of mp3"
s "fq . file.mp3"
echo
c "Show ID3v2 tag in mp3 file"
s "fq '.headers[0]' file.mp3"
echo
c "Resolution of ID3v2 cover art"
s "fq '.headers[0].frames[] | select(.id == \"APIC\").picture.chunks[] | select(.type == \"IHDR\") | {width, height}' file.mp3"
echo
c "Extract image file"
s "fq '.headers[].frames[] | select(.id == \"APIC\")?.picture | tobits' file.mp3 >file.png"
s "file file.png"
rm -f file.png

0 comments on commit 4cee498

Please sign in to comment.