message: utils: enhance zran interface for ease of use
  Enhance zran interface for ease of use.
diff: @@ -38,6 +38,10 @@ pub struct ZranChunkInfo {
  pub ci_offset: u32,
  /// Size of the uncompressed chunk data.
  pub ci_len: u32,
  + /// Position in the compressed data stream.
  + pub in_pos: u64,
  + /// Size of compressed data in input stream.
  + pub in_len: u32,
  }
  /// Context information to decode data from a random access slice.
  @@ -152,6 +156,7 @@ pub struct ZranGenerator<R> {
  max_uncomp_size: u64,
  curr_block_start: u64,
  curr_ci_offset: u64,
  + curr_in_offset: u64,
  curr_ci_idx: Option<usize>,
  ci_array: Vec<ZranContext>,
  }
  @@ -166,6 +171,7 @@ impl<R: Read> ZranGenerator<R> {
  max_uncomp_size: ZRAN_MAX_UNCOMP_SIZE,
  curr_block_start: 0,
  curr_ci_offset: 0,
  + curr_in_offset: 0,
  curr_ci_idx: None,
  ci_array: Vec::new(),
  }
  @@ -206,6 +212,7 @@ impl<R: Read> ZranGenerator<R> {
  } else {
  self.curr_ci_idx = Some(ci_idx);
  self.curr_ci_offset = info.out_pos;
  + self.curr_in_offset = info.in_pos;
  Ok(ci_idx as u32)
  }
  }
  @@ -218,16 +225,12 @@ impl<R: Read> ZranGenerator<R> {
  let ctx = &mut self.ci_array[idx];
  let comp_size = info.in_pos - ctx.in_offset;
  let uncomp_size = info.out_pos - ctx.out_offset;
  - /*
  - if uncomp_size > self.max_uncomp_size || comp_size > self.max_comp_size {
  - return Err(einval!("uncompressed data size is too big"));
  - }
  - */
  -
  let ci = ZranChunkInfo {
  ci_index: idx as u32,
  ci_offset: (self.curr_ci_offset - ctx.out_offset) as u32,
  ci_len: (info.out_pos - self.curr_ci_offset) as u32,
  + in_pos: self.curr_in_offset,
  + in_len: (info.in_pos - self.curr_in_offset) as u32,
  };
  ctx.out_len = uncomp_size as u32;
  ctx.in_len = comp_size as u32;
  @@ -238,8 +241,7 @@ impl<R: Read> ZranGenerator<R> {
  }
  /// Get an immutable reference to the random access context information array.
  - pub fn get_compression_ctx_array(&mut self) -> &[ZranContext] {
  - self.curr_ci_idx = None;
  + pub fn get_compression_ctx_array(&self) -> &[ZranContext] {
  &self.ci_array
  }
  @@ -278,6 +280,12 @@ impl<R: Read> ZranGenerator<R> {
  }
  }
  +impl<R: Read> Read for ZranGenerator<R> {
  + fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  + self.reader.read(buf)
  + }
  +}
  +
  /// A specialized gzip reader for OCI image tarballs.
  ///
  /// This reader assumes that the compressed file is a tar file, and restricts access patterns.
  @@ -780,10 +788,10 @@ mod tests {
  let _start = generator.begin_read(512).unwrap();
  let mut buf = vec![0u8; 512];
  let sz = entry.read(&mut buf).unwrap();
  - let _info = generator.end_read().unwrap();
  if sz == 0 {
  break;
  }
  + let _info = generator.end_read().unwrap();
  }
  }
  }
  