Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use super::Db; |
| 2 | −use crate::{hash, loose, zlib::stream::DeflateWriter}; | |
| 2 | +use crate::{hash, loose, zlib::stream::deflate}; | |
| 3 | 3 | use std::{fs, io, io::Write, path::PathBuf}; |
| 4 | 4 | use tempfile::NamedTempFile; |
| 5 | 5 | |
| @@ -73,7 +73,7 @@ impl crate::Write for Db { · 67 unmodified lines | ||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | −type HashAndTempFile = DeflateWriter<NamedTempFile>; | |
| 76 | +type CompressedTempfile = deflate::Writer<NamedTempFile>; | |
| 77 | 77 | |
| 78 | 78 | impl Db { |
| 79 | 79 | fn write_header( |
| @@ -81,9 +81,9 @@ impl Db { · 1 unmodified line | ||
| 81 | 81 | kind: git_object::Kind, |
| 82 | 82 | size: u64, |
| 83 | 83 | hash: git_hash::Kind, |
| 84 | − ) -> Result<hash::Write<HashAndTempFile>, Error> { | |
| 84 | + ) -> Result<hash::Write<CompressedTempfile>, Error> { | |
| 85 | 85 | let mut to = hash::Write::new( |
| 86 | − DeflateWriter::new(NamedTempFile::new_in(&self.path).map_err(|err| Error::Io { | |
| 86 | + deflate::Writer::new(NamedTempFile::new_in(&self.path).map_err(|err| Error::Io { | |
| 87 | 87 | source: err, |
| 88 | 88 | message: "create named temp file in", |
| 89 | 89 | path: self.path.to_owned(), |
| @@ -101,7 +101,7 @@ impl Db { · 11 unmodified lines | ||
| 101 | 101 | |
| 102 | 102 | fn finalize_object( |
| 103 | 103 | &self, |
| 104 | − hash::Write { hash, inner: file }: hash::Write<HashAndTempFile>, | |
| 104 | + hash::Write { hash, inner: file }: hash::Write<CompressedTempfile>, | |
| 105 | 105 | ) -> Result<git_hash::ObjectId, Error> { |
| 106 | 106 | let id = git_hash::ObjectId::from(hash.digest()); |
| 107 | 107 | let object_path = loose::db::sha1_path(&id, self.path.clone()); |
| @@ -56,7 +56,7 @@ pub mod entry { · 55 unmodified lines | ||
| 56 | 56 | entry_kind: Kind::Base, |
| 57 | 57 | decompressed_size: obj.data.len(), |
| 58 | 58 | compressed_data: { |
| 59 | − let mut out = crate::zlib::stream::DeflateWriter::new(Vec::new()); | |
| 59 | + let mut out = crate::zlib::stream::deflate::Writer::new(Vec::new()); | |
| 60 | 60 | if let Err(err) = std::io::copy(&mut &obj.data[..], &mut out) { |
| 61 | 61 | match err.kind() { |
| 62 | 62 | std::io::ErrorKind::Other => return Err(Error::ZlibDeflate(err.to_string())), |
| @@ -1,4 +1,4 @@ | ||
| 1 | −use crate::{loose, zlib::stream::DeflateWriter}; | |
| 1 | +use crate::{loose, zlib::stream::deflate}; | |
| 2 | 2 | use std::{ |
| 3 | 3 | cell::RefCell, |
| 4 | 4 | convert::TryInto, |
| @@ -10,14 +10,14 @@ use std::{ · 5 unmodified lines | ||
| 10 | 10 | /// It can optionally compress the content, similarly to what would happen when using a [`loose::Db`]. |
| 11 | 11 | /// |
| 12 | 12 | pub struct Sink { |
| 13 | − compressor: Option<RefCell<DeflateWriter<io::Sink>>>, | |
| 13 | + compressor: Option<RefCell<deflate::Writer<io::Sink>>>, | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | impl Sink { |
| 17 | 17 | /// Enable or disable compression. Compression is disabled by default |
| 18 | 18 | pub fn compress(mut self, enable: bool) -> Self { |
| 19 | 19 | if enable { |
| 20 | − self.compressor = Some(RefCell::new(DeflateWriter::new(io::sink()))); | |
| 20 | + self.compressor = Some(RefCell::new(deflate::Writer::new(io::sink()))); | |
| 21 | 21 | } else { |
| 22 | 22 | self.compressor = None; |
| 23 | 23 | } |
| @@ -3,18 +3,18 @@ use std::io; · 2 unmodified lines | ||
| 3 | 3 | |
| 4 | 4 | const BUF_SIZE: usize = 4096 * 8; |
| 5 | 5 | |
| 6 | −pub struct DeflateWriter<W> { | |
| 6 | +pub struct Writer<W> { | |
| 7 | 7 | compressor: Compress, |
| 8 | 8 | inner: W, |
| 9 | 9 | buf: [u8; BUF_SIZE], |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | −impl<W> DeflateWriter<W> | |
| 12 | +impl<W> Writer<W> | |
| 13 | 13 | where |
| 14 | 14 | W: io::Write, |
| 15 | 15 | { |
| 16 | − pub fn new(inner: W) -> DeflateWriter<W> { | |
| 17 | − DeflateWriter { | |
| 16 | + pub fn new(inner: W) -> Writer<W> { | |
| 17 | + Writer { | |
| 18 | 18 | compressor: Compress::new(Compression::fast(), true), |
| 19 | 19 | inner, |
| 20 | 20 | buf: [0; BUF_SIZE], |
| @@ -67,7 +67,7 @@ where · 46 unmodified lines | ||
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | −impl<W: io::Write> io::Write for DeflateWriter<W> { | |
| 70 | +impl<W: io::Write> io::Write for Writer<W> { | |
| 71 | 71 | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { |
| 72 | 72 | self.write_inner(buf, FlushCompress::None) |
| 73 | 73 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | mod deflate_stream { |
| 2 | − use crate::zlib::stream::DeflateWriter; | |
| 2 | + use crate::zlib::stream::deflate; | |
| 3 | 3 | use bstr::ByteSlice; |
| 4 | 4 | use flate2::Decompress; |
| 5 | 5 | use std::{ |
| @@ -52,7 +52,7 @@ mod deflate_stream { · 46 unmodified lines | ||
| 52 | 52 | |
| 53 | 53 | #[test] |
| 54 | 54 | fn all_at_once() -> Result<(), Box<dyn std::error::Error>> { |
| 55 | − let mut w = DeflateWriter::new(Vec::new()); | |
| 55 | + let mut w = deflate::Writer::new(Vec::new()); | |
| 56 | 56 | assert_eq!(w.write(b"hello")?, 5); |
| 57 | 57 | w.flush()?; |
| 58 | 58 | |
| @@ -71,7 +71,7 @@ mod deflate_stream { · 12 unmodified lines | ||
| 71 | 71 | |
| 72 | 72 | #[test] |
| 73 | 73 | fn big_file_small_writes() -> Result<(), Box<dyn std::error::Error>> { |
| 74 | − let mut w = DeflateWriter::new(Vec::new()); | |
| 74 | + let mut w = deflate::Writer::new(Vec::new()); | |
| 75 | 75 | let bytes = include_bytes!( |
| 76 | 76 | "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack" |
| 77 | 77 | ); |
| @@ -85,7 +85,7 @@ mod deflate_stream { · 7 unmodified lines | ||
| 85 | 85 | |
| 86 | 86 | #[test] |
| 87 | 87 | fn big_file_a_few_big_writes() -> Result<(), Box<dyn std::error::Error>> { |
| 88 | − let mut w = DeflateWriter::new(Vec::new()); | |
| 88 | + let mut w = deflate::Writer::new(Vec::new()); | |
| 89 | 89 | let bytes = include_bytes!( |
| 90 | 90 | "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack" |
| 91 | 91 | ); |
| @@ -1,5 +1,2 @@ | ||
| 1 | −pub mod inflate; | |
| 2 | − | |
| 3 | 1 | pub mod deflate; |
| 4 | −#[doc(inline)] | |
| 5 | −pub use deflate::DeflateWriter; | |
| 2 | +pub mod inflate; | |