cleanup: remove flate2 - files are pre-unzipped by the downloader
This commit is contained in:
parent
c415ffbdab
commit
a2939fbc0f
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -1,12 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
@ -185,25 +179,6 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.15"
|
||||
@ -294,7 +269,6 @@ version = "1.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"flate2",
|
||||
"lazy-regex",
|
||||
"rbx_binary",
|
||||
"rbx_dom_weak",
|
||||
@ -308,15 +282,6 @@ version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
@ -8,7 +8,6 @@ edition = "2021"
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
clap = { version = "4.4.2", features = ["derive"] }
|
||||
flate2 = "1.0.27"
|
||||
lazy-regex = "3.1.0"
|
||||
rbx_binary = { version = "0.7.4", registry = "strafesnet"}
|
||||
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet"}
|
||||
|
40
src/main.rs
40
src/main.rs
@ -94,23 +94,6 @@ fn get_script_refs(dom:&rbx_dom_weak::WeakDom) -> Vec<rbx_dom_weak::types::Ref>{
|
||||
scripts
|
||||
}
|
||||
|
||||
enum ReaderType<'a, R:Read+Seek>{
|
||||
GZip(flate2::read::GzDecoder<&'a mut R>),
|
||||
Raw(&'a mut R),
|
||||
}
|
||||
|
||||
fn maybe_gzip_decode<R:Read+Seek>(input:&mut R)->AResult<ReaderType<R>>{
|
||||
let mut first_2=[0u8;2];
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(input, &mut first_2),std::io::Seek::rewind(input)){
|
||||
match &first_2{
|
||||
b"\x1f\x8b"=>Ok(ReaderType::GZip(flate2::read::GzDecoder::new(input))),
|
||||
_=>Ok(ReaderType::Raw(input)),
|
||||
}
|
||||
}else{
|
||||
Err(anyhow::Error::msg("failed to peek"))
|
||||
}
|
||||
}
|
||||
|
||||
fn load_dom<R:Read+Seek>(input:&mut R)->AResult<rbx_dom_weak::WeakDom>{
|
||||
let mut first_8=[0u8;8];
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(input, &mut first_8),std::io::Seek::rewind(input)){
|
||||
@ -129,19 +112,6 @@ fn load_dom<R:Read+Seek>(input:&mut R)->AResult<rbx_dom_weak::WeakDom>{
|
||||
}
|
||||
}
|
||||
|
||||
fn get_dom<R:Read+Seek>(input:&mut R)->AResult<rbx_dom_weak::WeakDom>{
|
||||
match maybe_gzip_decode(input){
|
||||
Ok(ReaderType::GZip(mut readable)) => {
|
||||
//gzip
|
||||
let mut extracted:Vec<u8>=Vec::new();
|
||||
readable.read_to_end(&mut extracted)?;
|
||||
Ok(load_dom(&mut std::io::Cursor::new(extracted))?)
|
||||
},
|
||||
Ok(ReaderType::Raw(readable)) => Ok(load_dom(readable)?),
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_id() -> AResult<u32>{
|
||||
match std::fs::read_to_string("id"){
|
||||
Ok(id_file)=>Ok(id_file.parse::<u32>()?),
|
||||
@ -255,7 +225,7 @@ fn scan() -> AResult<()>{
|
||||
let file_thing=entry?;
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
|
||||
let dom = get_dom(&mut input)?;
|
||||
let dom = load_dom(&mut input)?;
|
||||
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
@ -313,7 +283,7 @@ fn extract_scripts(paths: Vec<PathBuf>) -> AResult<()>{
|
||||
let file_name=path.file_name();
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(&path)?);
|
||||
|
||||
let dom = get_dom(&mut input)?;
|
||||
let dom = load_dom(&mut input)?;
|
||||
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
@ -347,7 +317,7 @@ fn replace() -> AResult<()>{
|
||||
let file_thing=entry?;
|
||||
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let mut dom = get_dom(&mut input)?;
|
||||
let mut dom = load_dom(&mut input)?;
|
||||
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
@ -424,7 +394,7 @@ fn upload() -> AResult<()>{
|
||||
println!("map file: {:?}",file_thing.file_name());
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
|
||||
let dom = get_dom(&mut input)?;
|
||||
let dom = load_dom(&mut input)?;
|
||||
let (modelname,creator,displayname,_) = get_mapinfo(&dom)?;
|
||||
|
||||
//Creator: [auto fill creator]
|
||||
@ -564,7 +534,7 @@ fn interactive() -> AResult<()>{
|
||||
let file_thing=entry?;
|
||||
println!("processing map={:?}",file_thing.file_name());
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let mut dom = get_dom(&mut input)?;
|
||||
let mut dom = load_dom(&mut input)?;
|
||||
let (modelname,creator,displayname,displayname_ref)=get_mapinfo(&dom)?;
|
||||
|
||||
let mut script_count=0;
|
||||
|
Loading…
Reference in New Issue
Block a user