initial commit, bencode decoding
This commit is contained in:
24
examples/decode-torrent.rs
Normal file
24
examples/decode-torrent.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
extern crate magnolia;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read};
|
||||
use std::str;
|
||||
|
||||
use magnolia::bencode::*;
|
||||
|
||||
fn load_file(path: &str) -> io::Result<()> {
|
||||
let mut buf = Vec::new();
|
||||
let mut f = File::open(path)?;
|
||||
f.read_to_end(&mut buf)?;
|
||||
|
||||
let obj = decode(&buf).unwrap();
|
||||
println!("{:#?}", obj);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let path = env::args().nth(1).expect("need path to .torrent file");
|
||||
load_file(&path).unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user