Skip to content

Commit 4bed2ab

Browse files
committed
init
0 parents  commit 4bed2ab

File tree

4 files changed

+328
-0
lines changed

4 files changed

+328
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

Lines changed: 267 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "base65536"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
base65536 = "1.0.1"
8+
clap = { version = "4.5.36", features = ["derive"] }

src/main.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::fs::File;
2+
use std::io::{Read, Write, stdin, stdout};
3+
use std::path::PathBuf;
4+
5+
use clap::Parser;
6+
7+
#[derive(Parser)]
8+
struct Cli {
9+
#[clap(short, long)]
10+
decode: bool,
11+
12+
#[clap(short, long)]
13+
ignore_garbage: bool,
14+
15+
#[clap(short, long, default_value_t = 24)]
16+
wrap: usize,
17+
18+
#[clap(default_value = "-")]
19+
path: PathBuf,
20+
}
21+
22+
fn main() {
23+
let cli = Cli::parse();
24+
25+
let mut buffer = vec![];
26+
27+
if cli.path == PathBuf::from("-") {
28+
stdin()
29+
.lock()
30+
.read_to_end(&mut buffer)
31+
.expect("Failed to read stdin");
32+
} else {
33+
File::open(cli.path)
34+
.expect("Failed to open file")
35+
.read_to_end(&mut buffer)
36+
.expect("Failed to read file");
37+
};
38+
39+
if cli.decode {
40+
let buffer = String::from_utf8(buffer).expect("Failed to read as UTF-8 string");
41+
42+
let decoded =
43+
base65536::decode(&buffer, cli.ignore_garbage).expect("Failed to decode input");
44+
45+
stdout()
46+
.lock()
47+
.write_all(&decoded)
48+
.expect("Failed to write to stdout");
49+
} else {
50+
println!("{}", base65536::encode(&buffer, cli.wrap));
51+
}
52+
}

0 commit comments

Comments
 (0)