Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fixed error in compressing LZ4
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Nov 10, 2021
1 parent 37a9c75 commit 03fe941
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/io/ipc/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub fn decompress_zstd(_input_buf: &[u8], _output_buf: &mut [u8]) -> Result<()>
pub fn compress_lz4(input_buf: &[u8], output_buf: &mut Vec<u8>) -> Result<()> {
use std::io::Write;
let mut encoder = lz4::EncoderBuilder::new().build(output_buf).unwrap();
encoder.write_all(input_buf).map_err(|e| e.into())
encoder.write_all(input_buf)?;
encoder.finish().1.map_err(|e| e.into())
}

#[cfg(feature = "io_ipc_compression")]
Expand Down Expand Up @@ -62,7 +63,7 @@ mod tests {

#[cfg(feature = "io_ipc_compression")]
#[test]
fn round_trip() {
fn round_trip_zstd() {
let data: Vec<u8> = (0..200u8).map(|x| x % 10).collect();
let mut buffer = vec![];
compress_zstd(&data, &mut buffer).unwrap();
Expand All @@ -71,4 +72,16 @@ mod tests {
decompress_zstd(&buffer, &mut result).unwrap();
assert_eq!(data, result);
}

#[cfg(feature = "io_ipc_compression")]
#[test]
fn round_trip_lz4() {
let data: Vec<u8> = (0..200u8).map(|x| x % 10).collect();
let mut buffer = vec![];
compress_lz4(&data, &mut buffer).unwrap();

let mut result = vec![0; 200];
decompress_lz4(&buffer, &mut result).unwrap();
assert_eq!(data, result);
}
}

0 comments on commit 03fe941

Please sign in to comment.