/// Add a MIDI file to the archive
///
/// If adding the MIDI file breaks a partition or batch boundary,
/// this function will flush the current batch to the underlying tar
/// archive.
Add a MIDI file to the archive
If adding the MIDI file breaks a partition or batch boundary,
this function will flush the current batch to the underlying tar
archive.
Add a MIDI file to the archive If adding the MIDI file breaks a partition or batch boundary this function will flush the current batch to the underlying tar archive .
pub fn push(&mut self, mfile: libatm::MIDIFile) -> std::io::Result<()> {
        // Check archive state and panic if Closed
        self.assert_open();
        // Generate hash and partition
        let hash = mfile.gen_hash();
        let partition = gen_path(&hash, self.partition_size, self.partition_depth);
        // If partition has not been set (first batch)
        // or reached partition boundary
        if self.current_partition.is_empty() {
            self.current_partition = partition;
        } else if self.current_partition != partition {
            // Flush current batch to target archive
            self.flush()?;
            // Set new partition
            self.current_partition = partition;
        }
        // Add MIDI file to batch archive
        let mut header = tar::Header::new_old();
        header.set_size(mfile.gen_size() as u64);
        self.batch_archive.append_data(
            &mut header,
            format!("{}.mid", &hash),
            mfile.gen_buffer().unwrap().as_slice(),
        )?;
        // If reached batch boundary
        if self.gen_batch_size() == self.batch_size {
            // Flush current batch to target archive
            self.flush()?;
        }
        Ok(())
    }
pub fn push ( & mut self , mfile : libatm :: MIDIFile ) -> std :: io :: Result < ( ) > { // Check archive state and panic if Closed self . assert_open ( ) ; // Generate hash and partition let hash = mfile . gen_hash ( ) ; let partition = gen_path ( & hash , self . partition_size , self . partition_depth ) ; // If partition has not been set (first batch) // or reached partition boundary if self . current_partition . is_empty ( ) { self . current_partition = partition ; } else if self . current_partition != partition { // Flush current batch to target archive self . flush ( ) ? ; // Set new partition self . current_partition = partition ; } // Add MIDI file to batch archive let mut header = tar :: Header :: new_old ( ) ; header . set_size ( mfile . gen_size ( ) as u64 ) ; self . batch_archive . append_data ( & mut header , format ! ( " " hash ) , mfile . gen_buffer ( ) . unwrap ( ) . as_slice ( ) , ) ? ; // If reached batch boundary if self . gen_batch_size ( ) == self . batch_size { // Flush current batch to target archive self . flush ( ) ? ; } Ok ( ( ) ) }
Add a MIDI file to the archive
If adding the MIDI file breaks a partition or batch boundary,
this function will flush the current batch to the underlying tar
archive.
Add a MIDI file to the archive If adding the MIDI file breaks a partition or batch boundary this function will flush the current batch to the underlying tar archive .
&mut self
mfile
libatm::MIDIFile