Write a data block: compress, compute CRC, write block + trailer.
(&mut self)
| 115 | |
| 116 | /// Write a data block: compress, compute CRC, write block + trailer. |
| 117 | async fn write_block_data(&mut self) -> io::Result<BlockHandle> { |
| 118 | let block = self.data_block_writer.finish(); |
| 119 | |
| 120 | let (final_data, block_compression_type) = self.maybe_compress(&block); |
| 121 | |
| 122 | let crc = compute_crc32(&final_data, block_compression_type); |
| 123 | let trailer = BlockTrailer { |
| 124 | compression_type: block_compression_type, |
| 125 | crc32c: crc, |
| 126 | }; |
| 127 | |
| 128 | let block_handle = BlockHandle::new(self.bytes_written, final_data.len() as u32); |
| 129 | |
| 130 | self.write_bytes(&final_data).await?; |
| 131 | self.write_bytes(&trailer.to_bytes()).await?; |
| 132 | |
| 133 | Ok(block_handle) |
| 134 | } |
| 135 | |
| 136 | fn maybe_compress<'a>(&self, block: &'a [u8]) -> (Cow<'a, [u8]>, BlockCompressionType) { |
| 137 | match self.compression_type { |
no test coverage detected