History

refactor zlib

Sebastian Thiel committed 5 years ago

Commit 496e6bb1 parent 3a4469c6 files · +19 −22Browse files

Unified · Split

6 files
  1. git-odb/src/loose/db/write.rs +5 −5
  2. git-odb/src/pack/data/encode.rs +1 −1
  3. git-odb/src/sink.rs +3 −3
  4. git-odb/src/zlib/stream/deflate.rs +5 −5
  5. git-odb/src/zlib/stream/deflate/tests.rs +4 −4
  6. git-odb/src/zlib/stream/mod.rs +1 −4
git-odb/src/loose/db/write.rs+5−5
@@ -1,5 +1,5 @@
11 use super::Db;
2−use crate::{hash, loose, zlib::stream::DeflateWriter};
2+use crate::{hash, loose, zlib::stream::deflate};
33 use std::{fs, io, io::Write, path::PathBuf};
44 use tempfile::NamedTempFile;
55
@@ -73,7 +73,7 @@ impl crate::Write for Db { · 67 unmodified lines
7373 }
7474 }
7575
76−type HashAndTempFile = DeflateWriter<NamedTempFile>;
76+type CompressedTempfile = deflate::Writer<NamedTempFile>;
7777
7878 impl Db {
7979 fn write_header(
@@ -81,9 +81,9 @@ impl Db { · 1 unmodified line
8181 kind: git_object::Kind,
8282 size: u64,
8383 hash: git_hash::Kind,
84− ) -> Result<hash::Write<HashAndTempFile>, Error> {
84+ ) -> Result<hash::Write<CompressedTempfile>, Error> {
8585 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 {
8787 source: err,
8888 message: "create named temp file in",
8989 path: self.path.to_owned(),
@@ -101,7 +101,7 @@ impl Db { · 11 unmodified lines
101101
102102 fn finalize_object(
103103 &self,
104− hash::Write { hash, inner: file }: hash::Write<HashAndTempFile>,
104+ hash::Write { hash, inner: file }: hash::Write<CompressedTempfile>,
105105 ) -> Result<git_hash::ObjectId, Error> {
106106 let id = git_hash::ObjectId::from(hash.digest());
107107 let object_path = loose::db::sha1_path(&id, self.path.clone());
git-odb/src/pack/data/encode.rs+1−1
@@ -56,7 +56,7 @@ pub mod entry { · 55 unmodified lines
5656 entry_kind: Kind::Base,
5757 decompressed_size: obj.data.len(),
5858 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());
6060 if let Err(err) = std::io::copy(&mut &obj.data[..], &mut out) {
6161 match err.kind() {
6262 std::io::ErrorKind::Other => return Err(Error::ZlibDeflate(err.to_string())),
git-odb/src/sink.rs+3−3
@@ -1,4 +1,4 @@
1−use crate::{loose, zlib::stream::DeflateWriter};
1+use crate::{loose, zlib::stream::deflate};
22 use std::{
33 cell::RefCell,
44 convert::TryInto,
@@ -10,14 +10,14 @@ use std::{ · 5 unmodified lines
1010 /// It can optionally compress the content, similarly to what would happen when using a [`loose::Db`].
1111 ///
1212 pub struct Sink {
13− compressor: Option<RefCell<DeflateWriter<io::Sink>>>,
13+ compressor: Option<RefCell<deflate::Writer<io::Sink>>>,
1414 }
1515
1616 impl Sink {
1717 /// Enable or disable compression. Compression is disabled by default
1818 pub fn compress(mut self, enable: bool) -> Self {
1919 if enable {
20− self.compressor = Some(RefCell::new(DeflateWriter::new(io::sink())));
20+ self.compressor = Some(RefCell::new(deflate::Writer::new(io::sink())));
2121 } else {
2222 self.compressor = None;
2323 }
git-odb/src/zlib/stream/deflate.rs+5−5
@@ -3,18 +3,18 @@ use std::io; · 2 unmodified lines
33
44 const BUF_SIZE: usize = 4096 * 8;
55
6−pub struct DeflateWriter<W> {
6+pub struct Writer<W> {
77 compressor: Compress,
88 inner: W,
99 buf: [u8; BUF_SIZE],
1010 }
1111
12−impl<W> DeflateWriter<W>
12+impl<W> Writer<W>
1313 where
1414 W: io::Write,
1515 {
16− pub fn new(inner: W) -> DeflateWriter<W> {
17− DeflateWriter {
16+ pub fn new(inner: W) -> Writer<W> {
17+ Writer {
1818 compressor: Compress::new(Compression::fast(), true),
1919 inner,
2020 buf: [0; BUF_SIZE],
@@ -67,7 +67,7 @@ where · 46 unmodified lines
6767 }
6868 }
6969
70−impl<W: io::Write> io::Write for DeflateWriter<W> {
70+impl<W: io::Write> io::Write for Writer<W> {
7171 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
7272 self.write_inner(buf, FlushCompress::None)
7373 }
git-odb/src/zlib/stream/deflate/tests.rs+4−4
@@ -1,5 +1,5 @@
11 mod deflate_stream {
2− use crate::zlib::stream::DeflateWriter;
2+ use crate::zlib::stream::deflate;
33 use bstr::ByteSlice;
44 use flate2::Decompress;
55 use std::{
@@ -52,7 +52,7 @@ mod deflate_stream { · 46 unmodified lines
5252
5353 #[test]
5454 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());
5656 assert_eq!(w.write(b"hello")?, 5);
5757 w.flush()?;
5858
@@ -71,7 +71,7 @@ mod deflate_stream { · 12 unmodified lines
7171
7272 #[test]
7373 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());
7575 let bytes = include_bytes!(
7676 "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
7777 );
@@ -85,7 +85,7 @@ mod deflate_stream { · 7 unmodified lines
8585
8686 #[test]
8787 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());
8989 let bytes = include_bytes!(
9090 "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
9191 );
git-odb/src/zlib/stream/mod.rs+1−4
@@ -1,5 +1,2 @@
1−pub mod inflate;
2−
31 pub mod deflate;
4−#[doc(inline)]
5−pub use deflate::DeflateWriter;
2+pub mod inflate;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t