Skip to content

Commit 40a439d

Browse files
committed
Added references to the jq streaming form as implementation notes
1 parent e9722ad commit 40a439d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ String length as the count of UTF-16 code units needed to encode the string. Eac
3636
`u16strbencode/0`: JSON to Bencode conversion
3737
`u16strbdecode/0`: Bencode to JSON conversion
3838

39+
## Implementation notes
40+
41+
The actual implementation of the encoder/decoder relies on `jq`'s [streaming parsing](https://stedolan.github.io/jq/manual/#Streaming), which turns a data structure into a list of path expressions, some of them with leaf values, some of them not.
42+
The internal `_bencode` function takes a streaming form of the JSON input and through `reduce` processes it generating the Bencode-d output.
43+
The internal `_bdecode` function instead processes the Bencode-d string character by character through `reduce`, generating a streaming JSON form which is converted to a JSON data structure via `fromstream` at the end.
44+
3945
## Examples
4046

4147
After copying `bencode.jq` in one of the directories of the `jq` modules search path (see `jq`'s documentation) or using `jq`'s `-L` option to reference the directory containing the module file:

0 commit comments

Comments
 (0)