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
4mod db;4mod db;
5mod object;5mod object;
6 6
7pub 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
7pub use db::{Db, Error as DbError};31pub use db::{Db, Error as DbError};
8pub use object::*;32pub use object::*;
git-odb/src/loose/object.rs+4−4
@@ -1,5 +1,5 @@
1use crate::zlib::stream::InflateReader;
2use crate::{1use crate::{
2 loose::io::ObjectReader,
3 loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},3 loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},
4 zlib,4 zlib,
5};5};
@@ -8,7 +8,6 @@ use miniz_oxide::inflate::decompress_to_vec_zlib; · 2 unmodified lines
8use object::borrowed;8use object::borrowed;
9use quick_error::quick_error;9use quick_error::quick_error;
10use smallvec::SmallVec;10use smallvec::SmallVec;
11use std::io::BufReader;
12use std::{io::Read, path::PathBuf};11use std::{io::Read, path::PathBuf};
13 12
14quick_error! {13quick_error! {
@@ -56,9 +55,10 @@ impl Object { · 41 unmodified lines
56 })55 })
57 }56 }
58 57
59 pub fn stream(&self) -> Result<InflateReader<BufReader<std::fs::File>>, Error> {58 pub fn stream(&self) -> Result<ObjectReader, Error> {
60 match &self.path {59 match &self.path {
61 Some(path) => Ok(InflateReader::new(60 Some(path) => Ok(ObjectReader::from_read(
61 self.header_size,
62 std::fs::File::open(path).map_err(|e| Error::Io(e, "open", path.to_owned()))?,62 std::fs::File::open(path).map_err(|e| Error::Io(e, "open", path.to_owned()))?,
63 )),63 )),
64 None => unimplemented!("stream with buffer"),64 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