Skip to content

Commit

Permalink
use seek and read
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-de committed Feb 5, 2021
1 parent a8bb46b commit a38ba99
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/read_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::{
use failure::{format_err, ResultExt};
use log::info;
use serde::Deserialize;
use std::collections::BTreeMap;
use std::fs::File;
use std::path;
use std::path::{Path, PathBuf};
use std::{collections::BTreeMap, io::Read};
use std::{fs::File, io::Seek};
use typed_index_collection::{CollectionWithId, Id};

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -97,7 +97,7 @@ pub(crate) trait FileHandler
where
Self: std::marker::Sized,
{
type Reader: std::io::Read;
type Reader: Read;

fn get_file_if_exists(self, name: &str) -> Result<(Option<Self::Reader>, PathBuf)>;

Expand Down Expand Up @@ -142,15 +142,15 @@ impl<'a, P: AsRef<Path>> FileHandler for &'a mut PathFileHandler<P> {
/// Unlike ZipArchive, it gives access to a file by its name not regarding its path in the ZipArchive
/// It thus cannot be correct if there are 2 files with the same name in the archive,
/// but for transport data if will make it possible to handle a zip with a sub directory
pub(crate) struct ZipHandler<R: std::io::Seek + std::io::Read> {
pub(crate) struct ZipHandler<R: Seek + Read> {
archive: zip::ZipArchive<R>,
archive_path: PathBuf,
index_by_name: BTreeMap<String, usize>,
}

impl<R> ZipHandler<R>
where
R: std::io::Seek + std::io::Read,
R: Seek + Read,
{
pub(crate) fn new<P: AsRef<Path>>(r: R, path: P) -> Result<Self> {
let mut archive = zip::ZipArchive::new(r)?;
Expand All @@ -176,7 +176,7 @@ where

impl<'a, R> FileHandler for &'a mut ZipHandler<R>
where
R: std::io::Seek + std::io::Read,
R: Seek + Read,
{
type Reader = zip::read::ZipFile<'a>;
fn get_file_if_exists(self, name: &str) -> Result<(Option<Self::Reader>, PathBuf)> {
Expand Down

0 comments on commit a38ba99

Please sign in to comment.