Skip to content

Commit a94bc2f

Browse files
committed
wordlist: Compress embedded wordlist using zstd
1 parent 906391d commit a94bc2f

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

Cargo.lock

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

crates/strings/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wordlist.zst

crates/strings/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ quicktag-core = { path = "../core" }
99
anyhow.workspace = true
1010
binrw.workspace = true
1111
bytemuck = "1"
12+
lazy_static = "1.4.0"
1213
log.workspace = true
1314
rustc-hash.workspace = true
1415
tiger-pkg.workspace = true
16+
zstd = { version = "0.13.3", default-features = false }
17+
18+
[build-dependencies]
19+
zstd = { version = "0.13.3", default-features = false }

crates/strings/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::{fs::File, io::BufReader};
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=build.rs");
5+
println!("cargo:rerun-if-changed=../../wordlist.txt");
6+
7+
let source =
8+
BufReader::new(File::open("../../wordlist.txt").expect("Failed to open wordlist.txt"));
9+
let destination = File::create("wordlist.zst").expect("Failed to create wordlist.zst");
10+
zstd::stream::copy_encode(source, destination, 11).expect("Failed to compress wordlist.txt");
11+
}

crates/strings/src/wordlist.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
use std::{io::BufRead, time::Instant};
22

3+
use lazy_static::lazy_static;
34
use log::{error, info};
45
use quicktag_core::util::{FNV1_BASE, fnv1};
56

6-
const WORDLIST: &str = include_str!("../../../wordlist.txt");
7+
lazy_static! {
8+
static ref WORDLIST: String = {
9+
info!("Decompressing wordlist...");
10+
const DATA: &[u8] = include_bytes!("../wordlist.zst");
11+
let decompressed = zstd::stream::decode_all(&mut std::io::Cursor::new(DATA)).unwrap();
12+
String::from_utf8(decompressed).unwrap()
13+
};
14+
}
715

816
pub fn load_wordlist<F: FnMut(&str, u32)>(mut callback: F) {
917
let load_start = Instant::now();

0 commit comments

Comments
 (0)