Skip to content

Commit 6ea1ae9

Browse files
committed
Improved docs, removed unnecessesary deps
1 parent d342d72 commit 6ea1ae9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Torrent Parser
1+
> :warning:This project is still a WIP :warning:
2+
3+
# Bencode Parser
24

35
A bencode parser written in Rust
46

src/bencode.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
//!
33
//! ## Example
44
//! ```rust
5-
//! let res: BEncode = BEncode::parse("./src/Hello.txt");
5+
//! let path: PathBuf = PathBuf::from("./src/Hello.txt");
6+
//! let bytes = fs::read(path).expect("Couldn't Read File!");
7+
//! let res: BEncode = BEncode::parse(bytes);
68
//! println!("Decoded Object: {:?}", res);
79
//!
810
//! ```
911
1012
use std::cmp::Ordering;
1113
use std::collections::HashMap;
12-
use std::path::PathBuf;
13-
use std::{fmt, fs};
14+
use std::fmt;
1415

1516
/// The BEncode Object.
1617
/// This enum wraps the data types supported by bencode objects, with an addition of `String`.
@@ -46,10 +47,7 @@ impl fmt::Debug for BEncode {
4647
impl BEncode {
4748
/// This function returns the parsed [`BEncode`] object, given a valid path to a file containing bencode.
4849
/// returns a `Bencode::Int(-1)` if the bencode cannot be parsed
49-
pub fn parse(file_path: &str) -> Self {
50-
let path: PathBuf = PathBuf::from(file_path);
51-
let bytes = fs::read(path).expect("Couldn't Read File!");
52-
50+
pub fn parse(bytes: Vec<u8>) -> Self {
5351
// =====================STATE VARIABLES==========================
5452
let mut parents: Vec<BEncode> = Vec::new();
5553
let mut dict_keys: Vec<String> = Vec::new();

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ fn main() {
2727
return;
2828
}
2929

30-
let res: BEncode = BEncode::parse(&args.input);
30+
let path: PathBuf = PathBuf::from(&args.input);
31+
let bytes = fs::read(path).expect("Couldn't Read File!");
32+
33+
let res: BEncode = BEncode::parse(bytes);
3134

3235
if let BEncode::Dictionary(_) = res {
3336
let file_path: PathBuf = PathBuf::from(args.output);

0 commit comments

Comments
 (0)