forked from ckamm/solana-accountsdb-connector
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Nader-Sl/v1.10
Adds optional zstd compression to account data
- Loading branch information
Showing
4 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::io::{Read, Write}; | ||
|
||
pub fn zstd_compress(data: &[u8]) -> Result<Vec<u8>, std::io::Error> { | ||
let mut encoder = zstd::stream::write::Encoder::new(Vec::new(), 0).unwrap(); | ||
encoder.write_all(data)?; | ||
encoder.finish() | ||
} | ||
|
||
pub fn zstd_decompress(data: &[u8], uncompressed: &mut Vec<u8>) -> Result<usize, std::io::Error> { | ||
let mut decoder = zstd::stream::read::Decoder::new(data).unwrap(); | ||
decoder.read_to_end(uncompressed) | ||
} | ||
|
||
pub(crate) mod tests { | ||
use super::*; | ||
#[test] | ||
fn test_zstd_compression() { | ||
let data = vec![100; 256]; //sample data, 256 bytes of val 100. | ||
println!("Uncompressed Data = {:?}", data); | ||
|
||
match zstd_compress(&data) { | ||
Ok(compressed) => { | ||
println!("Compressed Data = {:?}\n", compressed); | ||
|
||
let mut uncompressed: Vec<u8> = Vec::new(); | ||
|
||
match zstd_decompress(&compressed, &mut uncompressed) { | ||
Ok(_) => { | ||
println!("Uncompressed Data = {:?}\n", uncompressed); | ||
} | ||
Err(e) => { | ||
println!("Error = {:?}", e); | ||
} | ||
} | ||
} | ||
Err(e) => { | ||
println!("Error compressing Data {:?}", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod compression; | ||
pub mod accounts_selector; | ||
pub mod geyser_plugin_grpc; |