Bencode parsing library
Api
bencode::result_type = bencode::parse_file(path_to_bencoded_file) bencode::result_type = bencode::parse_content(bencoded_content) bencode::Metadata = bencode::extract_metadata(bencode::result_type) // utility - useful for regex/grep std::string = bencode::convert_to_string(bencode::Metadata) // standard compliant std::string = bencode::convert_to_string(bencode::result_type) // may contain non standard dictionary values // See the header file for more details about the types
Examples
See examples/example.cc
Installation
Just include bencode_parser.hParsing Mode
Pass any of these enum constants to the functions mentioned in Api.Building test
bencode::Parsing_Mode::Strict (default) to consider any syntax error as fatal and throw. bencode::Parsing_Mode::Lenient to ignore as many errors as possible.
git clone https://github.com/alyanser/bencode-parser cd bencode-parser cmake -B build && cmake --build build
Sample metadata result returned by bencode::convert_to_string
--- big-buck-bunny.torrent taken from https://webtorrent.io/free-torrents --- - Name : Big Buck Bunny - Content type : Directory - Total Size 276445467 - Announce URL : udp://tracker.leechers-paradise.org:6969 - Created by : WebTorrent - Creation date : 1490916601 - Comment : WebTorrent - Encoding : UTF-8 - Piece length : 262144 - Announce list : udp://tracker.leechers-paradise.org:6969 udp://tracker.coppersurfer.tk:6969 udp://tracker.opentrackr.org:1337 Files information: Path : Big Buck Bunny.en.srt Size : 140 Path : Big Buck Bunny.mp4 Size : 276134947 Path : poster.jpg Size : 310380