-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new binary to par torrent files
- Loading branch information
1 parent
b3fe7f9
commit 9381212
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug executable 'parse_torrent'", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/target/debug/parse_torrent", | ||
"args": ["./tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent"], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
} | ||
], | ||
"preLaunchTask": "cargo build", | ||
"miDebuggerPath": "/usr/bin/gdb", | ||
"linux": { | ||
"miDebuggerPath": "/usr/bin/gdb" | ||
}, | ||
"windows": { | ||
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe" | ||
}, | ||
"osx": { | ||
"miDebuggerPath": "/usr/local/bin/gdb" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Command line tool to parse a torrent file and print the decoded torrent. | ||
//! | ||
//! It's only used for debugging purposes. | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::{self, Read}; | ||
|
||
use serde_bencode::de::from_bytes; | ||
use serde_bencode::value::Value as BValue; | ||
use torrust_index_backend::utils::parse_torrent; | ||
|
||
fn main() -> io::Result<()> { | ||
let args: Vec<String> = env::args().collect(); | ||
if args.len() != 2 { | ||
eprintln!("Usage: cargo run --bin parse_torrent <PATH_TO_TORRENT_FILE>"); | ||
eprintln!("Example: cargo run --bin parse_torrent ./tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent"); | ||
std::process::exit(1); | ||
} | ||
|
||
println!("Reading the torrent file ..."); | ||
|
||
let mut file = File::open(&args[1])?; | ||
let mut bytes = Vec::new(); | ||
file.read_to_end(&mut bytes)?; | ||
|
||
println!("Decoding torrent with standard serde implementation ..."); | ||
|
||
match from_bytes::<BValue>(&bytes) { | ||
Ok(_value) => match parse_torrent::decode_torrent(&bytes) { | ||
Ok(torrent) => { | ||
println!("Parsed torrent: \n{torrent:#?}"); | ||
Ok(()) | ||
} | ||
Err(e) => Err(io::Error::new(io::ErrorKind::Other, format!("Error: invalid torrent!. {e}"))), | ||
}, | ||
Err(e) => Err(io::Error::new( | ||
io::ErrorKind::Other, | ||
format!("Error: invalid bencode data!. {e}"), | ||
)), | ||
} | ||
} |
Binary file added
BIN
+121 KB
tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent
Binary file not shown.