1
1
mirror of https://github.com/wader/fq.git synced 2024-11-09 13:07:03 +03:00
fq/format/bencode/bencode.jq
Mattias Wadman 87b2c6c10c help,doc: Use markdown for format documentation again
Markdown is used as is in online documentation and in cli the markdown decoder
is used to decode and the some jq code massages it into something cli friendly.

Was just too much of a mess to have doc in jq.
2022-09-11 00:53:29 +02:00

12 lines
368 B
Plaintext

def _bencode_torepr:
if .type == "string" then .value | tovalue
elif .type == "integer" then .value | tovalue
elif .type == "list" then .values | map(_bencode_torepr)
elif .type == "dictionary" then
( .pairs
| map({key: (.key | _bencode_torepr), value: (.value | _bencode_torepr)})
| from_entries
)
else error("unknown type \(.type)")
end;