/// Compresstimate up to `len` bytes from the seekable `input` stream,
/// returning an estimated compression ratio (currently based on lz4 level 1).
Compresstimate up to `len` bytes from the seekable `input` stream,
returning an estimated compression ratio (currently based on lz4 level 1).
Compresstimate up to ` len ` bytes from the seekable ` input ` stream returning an estimated compression ratio ( currently based on lz4 level 1 ) .
pub fn compresstimate_len<P: Read + Seek>(&self, mut input: P, len: u64) -> io::Result<f32> {
        let output = WriteCount::default();
        let mut encoder = EncoderBuilder::new().level(1).build(output)?;
        let blocks = len / self.block_size;
        let samples = sample_size(blocks, self.error_margin, self.confidence) as u64;
        let written;
        // If we're going to be randomly sampling a big chunk of the file anyway,
        // we might as well read in the lot.
        if samples == 0 || len < samples * self.block_size * 4 {
            written = std::io::copy(&mut input.take(len), &mut encoder)?;
        } else {
            let step = self.block_size * (blocks / samples);
            let mut buf = vec![0; self.block_size as usize];
            written = self.block_size * samples;
            for i in 0..samples {
                input.seek(SeekFrom::Start(step * i))?;
                input.read_exact(&mut buf)?;
                encoder.write_all(&buf)?;
            }
        }
        let (output, result) = encoder.finish();
        result.map(|_| (output.written as f32 / written as f32).min(1.0))
    }
pub fn compresstimate_len < P : Read + Seek > ( & self , mut input : P , len : u64 ) -> io :: Result < f32 > { let output = WriteCount :: default ( ) ; let mut encoder = EncoderBuilder :: new ( ) . level ( 1 ) . build ( output ) ? ; let blocks = len / self . block_size ; let samples = sample_size ( blocks , self . error_margin , self . confidence ) as u64 ; let written ; // If we're going to be randomly sampling a big chunk of the file anyway, // we might as well read in the lot. if samples == 0 || len < samples * self . block_size * 4 { written = std :: io :: copy ( & mut input . take ( len ) , & mut encoder ) ? ; } else { let step = self . block_size * ( blocks / samples ) ; let mut buf = vec ! [ 0 self block_size as usize ] ; written = self . block_size * samples ; for i in 0 .. samples { input . seek ( SeekFrom :: Start ( step * i ) ) ? ; input . read_exact ( & mut buf ) ? ; encoder . write_all ( & buf ) ? ; } } let ( output , result ) = encoder . finish ( ) ; result . map ( | _ | ( output . written as f32 / written as f32 ) . min ( 1.0 ) ) }
Compresstimate up to `len` bytes from the seekable `input` stream,
returning an estimated compression ratio (currently based on lz4 level 1).
Compresstimate up to ` len ` bytes from the seekable ` input ` stream returning an estimated compression ratio ( currently based on lz4 level 1 ) .
&self
input
P
len
u64