History

first step towards supporting skipping the header in the stream

Sebastian Thiel committed 6 years ago

Commit 8e45f531 parent f10ed752 files · +28 −4Browse files

Unified · Split

2 files
  1. git-odb/src/loose/mod.rs +24 −0
  2. git-odb/src/loose/object.rs +4 −4
git-odb/src/loose/mod.rs+24−0
@@ -4,5 +4,29 @@ const HEADER_READ_UNCOMPRESSED_BYTES: usize = 512; · 3 unmodified lines
44 mod db;
55 mod object;
66
7+pub mod io {
8+ use crate::zlib::stream::InflateReader;
9+ use std::io::{BufReader, Bytes, Read};
10+ use std::iter::Skip;
11+
12+ pub enum ObjectReader {
13+ File(InflateReader<BufReader<std::fs::File>>),
14+ }
15+
16+ impl ObjectReader {
17+ pub fn from_read(header_size: usize, file: std::fs::File) -> ObjectReader {
18+ ObjectReader::File(InflateReader::new(file))
19+ }
20+ }
21+
22+ impl std::io::Read for ObjectReader {
23+ fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
24+ match self {
25+ ObjectReader::File(r) => r.read(buf),
26+ }
27+ }
28+ }
29+}
30+
731 pub use db::{Db, Error as DbError};
832 pub use object::*;
git-odb/src/loose/object.rs+4−4
@@ -1,5 +1,5 @@
1−use crate::zlib::stream::InflateReader;
21 use crate::{
2+ loose::io::ObjectReader,
33 loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},
44 zlib,
55 };
@@ -8,7 +8,6 @@ use miniz_oxide::inflate::decompress_to_vec_zlib; · 2 unmodified lines
88 use object::borrowed;
99 use quick_error::quick_error;
1010 use smallvec::SmallVec;
11−use std::io::BufReader;
1211 use std::{io::Read, path::PathBuf};
1312
1413 quick_error! {
@@ -56,9 +55,10 @@ impl Object { · 41 unmodified lines
5655 })
5756 }
5857
59− pub fn stream(&self) -> Result<InflateReader<BufReader<std::fs::File>>, Error> {
58+ pub fn stream(&self) -> Result<ObjectReader, Error> {
6059 match &self.path {
61− Some(path) => Ok(InflateReader::new(
60+ Some(path) => Ok(ObjectReader::from_read(
61+ self.header_size,
6262 std::fs::File::open(path).map_err(|e| Error::Io(e, "open", path.to_owned()))?,
6363 )),
6464 None => unimplemented!("stream with buffer"),

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