Skip to content

Commit

Permalink
Refactor: split image_store.rs into different files
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Viennot <[email protected]>
  • Loading branch information
nviennot committed Aug 25, 2021
1 parent dc36e36 commit a16447a
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 289 deletions.
289 changes: 0 additions & 289 deletions src/image_store.rs

This file was deleted.

53 changes: 53 additions & 0 deletions src/image_store/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020 Two Sigma Investments, LP.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::{ImageStore, ImageFile};
use anyhow::{Context, Result};
use std::{
fs,
path::Path,
};
use crate::{
unix_pipe::{UnixPipe, UnixPipeImpl},
};

pub struct Store<'a> {
images_dir: &'a Path,
}

impl<'a> Store<'a> {
pub fn new(images_dir: &'a Path) -> Self {
Self { images_dir }
}
}

impl ImageStore for Store<'_> {
type File = fs::File;

fn create(&mut self, filename: &str) -> Result<Self::File> {
let full_path = &self.images_dir.join(&filename);

let file = fs::File::create(full_path)
.with_context(|| format!("Failed to create file {}", full_path.display()))?;

Ok(file)
}
}

impl ImageFile for fs::File {
fn write_all_from_pipe(&mut self, shard_pipe: &mut UnixPipe, size: usize) -> Result<()> {
shard_pipe.splice_all(self, size)?;
Ok(())
}
}
Loading

0 comments on commit a16447a

Please sign in to comment.