-
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 #50 from bgpkit/zlib-ng
switch to zlib-ng for gzip file handling
- Loading branch information
Showing
2 changed files
with
24 additions
and
24 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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
use crate::oneio::compressions::OneIOCompression; | ||
use crate::OneIoError; | ||
use libflate::finish::AutoFinishUnchecked; | ||
use libflate::gzip::Decoder; | ||
use libflate::gzip::Encoder; | ||
use flate2::read::GzDecoder; | ||
use flate2::write::GzEncoder; | ||
use flate2::Compression; | ||
use std::fs::File; | ||
use std::io::{BufWriter, Read, Write}; | ||
|
||
pub(crate) struct OneIOGzip; | ||
|
||
impl OneIOCompression for OneIOGzip { | ||
fn get_reader(raw_reader: Box<dyn Read + Send>) -> Result<Box<dyn Read + Send>, OneIoError> { | ||
Ok(Box::new(Decoder::new(raw_reader)?)) | ||
Ok(Box::new(GzDecoder::new(raw_reader))) | ||
} | ||
|
||
fn get_writer(raw_writer: BufWriter<File>) -> Result<Box<dyn Write>, OneIoError> { | ||
// see libflate docs on the reasons of using [AutoFinishUnchecked]. | ||
let encoder = AutoFinishUnchecked::new(Encoder::new(raw_writer)?); | ||
let encoder = GzEncoder::new(raw_writer, Compression::default()); | ||
Ok(Box::new(encoder)) | ||
} | ||
} |