Skip to content

Commit ec6cc56

Browse files
committed
docs: update README
1 parent 68d9915 commit ec6cc56

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

README.md

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ Error: Unexpected end of input parsing integer; read context: input pos 3, lates
6565

6666
```console
6767
printf "3:ab" | cargo run
68-
Error: Unexpected end of input parsing string value; read context: input pos 4, latest input bytes dump: [51, 58, 97, 98] (UTF-8 string: `3:ab`); write context: output pos 0, latest output bytes dump: [] (UTF-8 string: ``)
68+
Error: Unexpected end of input parsing string value; read context: input pos 4, latest input bytes dump: [51, 58, 97, 98] (UTF-8 string: `3:ab`)
6969
```
7070

7171
```console
7272
echo "i00e" | cargo run
73-
Error: Leading zeros in integers are not allowed, for example b'i00e'; read context: byte `48` (char: `0`), input pos 3, latest input bytes dump: [105, 48, 48] (UTF-8 string: `i00`); write context: byte `48` (char: `0`), output pos 2, latest output bytes dump: [48, 48] (UTF-8 string: `00`)
73+
Error: Leading zeros in integers are not allowed, for example b'i00e'; read context: byte `48` (char: `0`), input pos 3, latest input bytes dump: [105, 48, 48] (UTF-8 string: `i00`)
7474
```
7575

7676
Generating pretty JSON with [jq][jq]:
@@ -111,36 +111,10 @@ cargo add bencode2json
111111

112112
There two ways of using the library:
113113

114-
- With high-level parser wrappers.
115-
- With the low-level parsers.
114+
- With high-level wrappers.
115+
- With the low-level generators.
116116

117-
Example using the high-level parser wrappers:
118-
119-
```rust
120-
use bencode2json::{try_bencode_to_json};
121-
122-
let result = try_bencode_to_json(b"d4:spam4:eggse").unwrap();
123-
124-
assert_eq!(result, r#"{"<string>spam</string>":"<string>eggs</<string>string>"}"#);
125-
```
126-
127-
Example using the low-level parser:
128-
129-
```rust
130-
use bencode2json::parsers::{BencodeParser};
131-
132-
let mut output = String::new();
133-
134-
let mut parser = BencodeParser::new(&b"4:spam"[..]);
135-
136-
parser
137-
.write_str(&mut output)
138-
.expect("Bencode to JSON conversion failed");
139-
140-
println!("{output}"); // It prints the JSON string: "<string>spam</string>"
141-
```
142-
143-
More [examples](./examples/).
117+
See [examples](./examples/).
144118

145119
## Test
146120

@@ -167,21 +141,19 @@ cargo cov
167141
## Performance
168142

169143
In terms of memory usage this implementation consumes at least the size of the
170-
biggest bencoded string. The string parser keeps all the string bytes in memory until
171-
it parses the whole string, in order to convert it to UTF-8, when it's possible.
144+
biggest bencoded integer or string. The string and integer parsers keeps all the bytes in memory until
145+
it parses the whole value.
172146

173147
The library also wraps the input and output streams in a [BufReader](https://doc.rust-lang.org/std/io/struct.BufReader.html)
174148
and [BufWriter](https://doc.rust-lang.org/std/io/struct.BufWriter.html) because it can be excessively inefficient to work directly with something that implements [Read](https://doc.rust-lang.org/std/io/trait.Read.html) or [Write](https://doc.rust-lang.org/std/io/trait.Write.html).
175149

176150
## TODO
177151

178-
- [ ] More examples of using the library.
179152
- [ ] Counter for number of items in a list for debugging and errors.
180153
- [ ] Fuzz testing: Generate random valid bencoded values.
181154
- [ ] Install tracing crate. Add verbose mode that enables debugging.
182155
- [ ] Option to check if the final JSON it's valid at the end of the process.
183156
- [ ] Benchmarking for this implementation and the original C implementation.
184-
- [ ] Optimize string parser. We can stop trying to convert the string to UTF-8 when we find a non valid UTF-8 char.
185157

186158
## Alternatives
187159

0 commit comments

Comments
 (0)