Skip to content

Commit

Permalink
fix:moved to rust native compression
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcomer committed Sep 1, 2020
1 parent 0d7fb66 commit 084e5d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
23 changes: 13 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ edition = '2018'
[dependencies]
anyhow = '1.0'
thiserror = '1.0'
rust-lzma = '0.5'
lru_time_cache = '0.10'
handlebars = '3.4'
itertools = '0.9'
Expand All @@ -40,6 +39,7 @@ bincode = '1.3'
lazy_static = '1'
riker = '0.4'
riker-patterns = '0.4'
compression = '0.1'

[dependencies.tokio]
version = '0.2'
Expand Down
13 changes: 11 additions & 2 deletions src/app/db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use compression::prelude::*;
use hogan::config::Environment;
use rusqlite::{params, Connection, OpenFlags, NO_PARAMS};
use serde::Deserialize;
Expand Down Expand Up @@ -35,7 +36,11 @@ pub fn read_sql_env(db_path: &str, env: &str, sha: &str) -> Result<Option<Enviro
let data: Option<rusqlite::Result<Vec<u8>>> =
query.query_map(params![key], |row| Ok(row.get(0)?))?.next();
if let Some(data) = data {
let decompressed_data = lzma::decompress(&data?)?;
let decompressed_data = data?
.iter()
.cloned()
.decode(&mut BZip2Decoder::new())
.collect::<Result<Vec<_>, _>>()?;
let decoded: WritableEnvironment = match bincode::deserialize(&decompressed_data) {
Ok(environment) => environment,
Err(e) => {
Expand All @@ -55,7 +60,11 @@ pub fn write_sql_env(db_path: &str, env: &str, sha: &str, data: &Environment) ->
let key = gen_env_key(sha, env);
let env_data: WritableEnvironment = data.into();
let data = bincode::serialize(&env_data)?;
let compressed_data = lzma::compress(&data, 6)?;
let compressed_data = data
.iter()
.cloned()
.encode(&mut BZip2Encoder::new(6), Action::Finish)
.collect::<Result<Vec<_>, _>>()?;
debug!(
"Writing to DB. Key: {} Size: {} -> {} = {}",
key,
Expand Down

0 comments on commit 084e5d9

Please sign in to comment.