#algorithm #pure #decompression #dcl #table #symbol #decode

implode

Pure Rust implementation of the DCL Implode algorithm. Currently, only decompression is supported.

2 releases

Uses old Rust 2015

0.1.1 Feb 11, 2018
0.1.0 Feb 11, 2018

#59 in #symbol

31 downloads per month
Used in mpq

MIT license

21KB
369 lines

implode

Pure Rust implementation of the DCL Implode algorithm.

Currently, this crate only supports decompression. Compression may be added based on the deflate crate in the future.


lib.rs:

Implementation of the PKWARE DCL Implode algorithm. Note that this is different from the Imploding algorithm in PKZIP. This implementation is based off of the one in zlib/contrib/blast.c, but uses lookup tables to decode the Shannon-Fano codes instead, which is way faster. This implementation uses no code from the PKWARE Data Compression Library (PKWARE DCL).

use implode::symbol::{Symbol, CodeTable, DEFAULT_CODE_TABLE, decode_bits};
use implode::exploder::Exploder;
use std::fs::File;
use std::io::Read;
use std::io::Write;

fn main() 
{
	let mut f = File::open("/path/to/input").expect("File open failed");
	let mut buf = [0u8; FILE_SIZE];
	f.read(&mut buf);
	let mut exploder = Exploder::new(&DEFAULT_CODE_TABLE);
	
	let mut ex = File::create("/path/to/output").expect("File create failed");
	let mut cpos: u32 = 0;
	let len = buf.len();
	let mut iter = 0;
	
	while !exploder.ended {
		
		let abuf = &mut buf[cpos as usize .. len];
		
		let x = exploder.explode_block(abuf).unwrap();
		cpos += x.0;
		
		//println!("{} {:?}",x.0, x.1);
		let bf = x.1;
	
		ex.write(bf);
		iter+=1;
	}
	
}

No runtime deps