| Crates.io | bencode_lib |
| lib.rs | bencode_lib |
| version | 0.1.7 |
| created_at | 2025-08-24 18:07:59.511932+00 |
| updated_at | 2025-11-30 19:11:54.451017+00 |
| description | Bencode library implementation. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1808644 |
| size | 251,213 |
A Rust library for parsing, constructing, and converting Bencode data. Designed for embedded systems, resource-constrained environments, and general-purpose use. Supports round-tripping Bencode and conversion to JSON, YAML, XML, and TOML.
Node)Node back to canonical BencodeNode to JSON, YAML, XML, or TOMLAdd to your Cargo.toml:
toml
[dependencies]
bencode_lib = "0.1.7"
toml
[dependencies]
bencode_lib = { path = "library" }
Parse a .torrent file and write as YAML:
use bencode_lib::{FileSource, FileDestination, parse, to_yaml};
let mut src = FileSource::new("example.torrent")?;
let node = parse(&mut src)?;
let mut dst = FileDestination::new("example.yaml")?;
to_yaml(&node, &mut dst);
Round-trip a Bencode buffer:
use bencode_lib::{BufferSource, BufferDestination, parse, stringify};
let raw = b"d3:foo3:bar4:spamli1ei2ei3eee".to_vec();
let mut src = BufferSource::new(raw);
let node = parse(&mut src)?;
let mut dst = BufferDestination::new();
stringify(&node, &mut dst);
Construct a Node and render as JSON:
use bencode_lib::{Node, to_json, BufferDestination};
let node = Node::from_dict(vec![
("info", Node::from_list(vec![Node::from_int(42), Node::from_str("hello")]))
]);
let mut dst = BufferDestination::new();
to_json(&node, &mut dst);
println!("{}", dst.to_string());
Node::Integer(i64)Node::String(Vec<u8>)Node::List(Vec<Node>)Node::Dict(Vec<(Vec<u8>, Node)>)FileSource, FileDestination, BufferSource, BufferDestinationNode, parse, stringifyto_json, to_yaml, to_xml, to_tomlversion, read_file, write_fileArena, MemoryTracker, StackBuffer, BencodeError, parse_borrowed, validate_bencodeParserConfig, EncoderConfigResult<Node, BencodeError>Result<_, BencodeError>docs/DEVELOPER_GUIDE.md for contributor infodocs/API_OVERVIEW.md for API detailsdocs/EMBEDDED_GUIDE.md for embedded usageexamples/MIT License. See LICENSE file for details.