3 releases

0.1.2 Jun 29, 2022
0.1.1 Jun 28, 2022
0.1.0 Jun 28, 2022

#2215 in Parser implementations

Download history 4/week @ 2024-02-14 24/week @ 2024-02-21 23/week @ 2024-02-28 6/week @ 2024-03-06 3/week @ 2024-03-13

58 downloads per month
Used in midwest_mainline

MIT license

12KB
148 lines

juicy_bencode

A little parser for bencode using the Nom library. Nom eats input byte by byte, and bencode is such juicy input!

The crate provides both more individual parses for parsing out individual bencode items or just a blob.

TL; DR

You have a bencoded blob containing the torrent information for totally legal files,

// pub enum BencodeItemView<'a> {
//     Integer(i64),
//     ByteString(&'a [u8]),
//     List(Vec<BencodeItemView<'a>>),
//     Dictionary(BTreeMap<&'a [u8], BencodeItemView<'a>>),
// }

use juicy_bencode::parse_bencode_dict;
fn main () -> Result<(), Box<dyn Error>>{
    // the library uses byte slices
    let text: &[u8] = input();
    // now you can do totally legal things with the info!
    let parsed_tree: BencodeItemView = parse_bencode_dict(text)?;
}

Dependencies

~2.5MB
~54K SLoC