Skip to content

Commit

Permalink
interp: Support force decode as -o force=true
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Feb 5, 2022
1 parent 6b88671 commit 366f6b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/usage.md
Expand Up @@ -50,6 +50,11 @@ fq 'grep_by(.type=="trak")' file
fq 'grep("^prefix")' file
fq 'grep(123)' file
fq 'grep_by(. >= 100 and . =< 100)' file

# decode file as mp4 and return a result even if there are some errors
fq -d mp4 file.mp4
# decode file as mp4 and also ignore validity assertions
fq -o force=true -d mp4 file.mp4
```

### Display output
Expand Down
2 changes: 2 additions & 0 deletions pkg/interp/options.jq
Expand Up @@ -37,6 +37,7 @@ def _opt_build_default_fixed:
expr_eval_path: "arg",
expr_file: null,
filenames: null,
force: false,
include_path: null,
join_string: "\n",
null_input: false,
Expand Down Expand Up @@ -120,6 +121,7 @@ def _opt_cli_arg_options:
expr: (.expr | _opt_tostring),
expr_file: (.expr_file | _opt_tostring),
filenames: (.filenames | _opt_toarray(type == "string")),
force: (.force | _opt_toboolean),
include_path: (.include_path | _opt_tostring),
join_string: (.join_string | _opt_tostring),
line_bytes: (.line_bytes | _opt_tonumber),
Expand Down
14 changes: 14 additions & 0 deletions pkg/interp/testdata/decode.fqtest
Expand Up @@ -53,6 +53,20 @@ $ fq -d raw 'tobytes[0:1] | png | d' /test.mp3
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: (png)
| | | error: png: RawLen(signature): failed at position 0 (read size 0 seek pos 0): outside buffer
0x0|49 |I | unknown0: raw bits
$ fq -o force=true -d png d /test.mp3
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: /test.mp3 (png)
| | | error: png: BitBufRange: failed at position 0 (read size 2315363 seek pos 0): outside buffer
0x000|49 44 33 04 00 00 00 00 |ID3..... | signature: raw bits (invalid)
| | | chunks[0:1]:
| | | [0]{}:
0x000| 00 23 54 53 | .#TS | length: 2315347
0x000| 53 45 00 00| SE..| type: "SE\x00\x00"
0x000| 53 | S | ancillary: true
0x000| 45 | E | private: false
0x000| 00 | . | reserved: false
0x000| 00| .| safe_to_copy: false
0x010|00 0f 00 00 03 4c 61 76 66 35 38 2e 34 35 2e 31|.....Lavf58.45.1| unknown0: raw bits
* |until 0x283.7 (end) (628) | |
$ fq -d raw 'tobytes[0:1] | try probe catch . | type' /test.mp3
"array"
$ fq -d raw 'png({force: true}) | d' /test.mp3
Expand Down
3 changes: 3 additions & 0 deletions pkg/interp/testdata/options.fqtest
Expand Up @@ -20,6 +20,7 @@ $ fq -n options
"filenames": [
null
],
"force": false,
"include_path": null,
"join_string": "\n",
"line_bytes": 16,
Expand Down Expand Up @@ -80,6 +81,8 @@ stderr:
error: open testdata/test.jq: no such file or directory
$ fq -o 'filenames=["/test.mp3"]' format
"mp3"
$ fq -o 'force=true' -n options.force
true
$ fq -o include_path=path -n options.include_path
"path"
$ fq -o 'join_string=aaa\n' -n options.join_string
Expand Down

0 comments on commit 366f6b1

Please sign in to comment.