update
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
extern crate magnolia;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::str;
|
||||
|
||||
use magnolia::bencode::*;
|
||||
use magnolia::metainfo::Metainfo;
|
||||
use magnolia::tracker::http;
|
||||
use magnolia::net::session::Session;
|
||||
|
||||
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();
|
||||
let meta = Metainfo::from_bencode(obj).unwrap();
|
||||
|
||||
println!("{}", meta.pieces.len());
|
||||
|
||||
let s = Session::new();
|
||||
s.add_torrent(meta);
|
||||
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let path = env::args().nth(1).expect("need path to .torrent file");
|
||||
load_file(&path).unwrap();
|
||||
}
|
||||
19
examples/print_metainfo.rs
Normal file
19
examples/print_metainfo.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
extern crate failure;
|
||||
extern crate magnolia;
|
||||
|
||||
use std::env;
|
||||
|
||||
use failure::Fail;
|
||||
use magnolia::metainfo::Metainfo;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
match Metainfo::open(&args[1]) {
|
||||
Ok(meta) => println!("{:?}", meta),
|
||||
Err(e) => {
|
||||
for cause in e.causes() {
|
||||
println!("{}", cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user