// Create a new pack stream for given dataobject
Create a new pack stream for given dataobject
Create a new pack stream for given dataobject
pub fn new_pack_stream(state: &State, data: Arc<Data>) -> Result<Box<PackStream>> {
    let data_ref = data.clone();
    Ok(match data.storage() {
        &Storage::Memory(_) => Box::new(MemoryPackStream {
            data: data_ref,
            position: 0,
        }),
        &Storage::Path(_) if data.is_blob() && data.size() == 0 => Box::new(EmptyPackStream {
            dummy: Default::default(),
        }),
        &Storage::Path(ref p) if data.is_blob() => Box::new(MmapPackStream {
            position: 0,
            mmap: unsafe { ::memmap::Mmap::map(&File::open(&p.path)?) }?,
        }),
        &Storage::Path(ref p) => {
            // TODO: Make tar in different thread
            assert!(data.is_directory());
            let temp_file = state.work_dir().make_temp_file();
            {
                let file = temp_file.create()?;
                let mut tar_builder = ::tar::Builder::new(file);
                tar_builder.mode(::tar::HeaderMode::Deterministic);
                tar_builder.append_dir_all(".", &p.path)?;
                tar_builder.finish()?;
            }
            Box::new(MmapPackStream {
                position: 0,
                mmap: unsafe { ::memmap::Mmap::map(&temp_file.open()?) }?,
            })
        }
    })
}
pub fn new_pack_stream ( state : & State , data : Arc < Data > ) -> Result < Box < PackStream > > { let data_ref = data . clone ( ) ; Ok ( match data . storage ( ) { & Storage :: Memory ( _ ) => Box :: new ( MemoryPackStream { data : data_ref , position : 0 , } ) , & Storage :: Path ( _ ) if data . is_blob ( ) && data . size ( ) == 0 => Box :: new ( EmptyPackStream { dummy : Default :: default ( ) , } ) , & Storage :: Path ( ref p ) if data . is_blob ( ) => Box :: new ( MmapPackStream { position : 0 , mmap : unsafe { :: memmap :: Mmap :: map ( & File :: open ( & p . path ) ? ) } ? , } ) , & Storage :: Path ( ref p ) => { // TODO: Make tar in different thread assert ! ( data is_directory ( ) ) ; let temp_file = state . work_dir ( ) . make_temp_file ( ) ; { let file = temp_file . create ( ) ? ; let mut tar_builder = :: tar :: Builder :: new ( file ) ; tar_builder . mode ( :: tar :: HeaderMode :: Deterministic ) ; tar_builder . append_dir_all ( " " , & p . path ) ? ; tar_builder . finish ( ) ? ; } Box :: new ( MmapPackStream { position : 0 , mmap : unsafe { :: memmap :: Mmap :: map ( & temp_file . open ( ) ? ) } ? , } ) } } ) }
Create a new pack stream for given dataobject
Create a new pack stream for given dataobject
state
&State
data
Arc<Data>