Put a key-value pair. Keys must be monotonically increasing.
(&mut self, key: &[u8], value: &[u8])
| 80 | |
| 81 | /// Put a key-value pair. Keys must be monotonically increasing. |
| 82 | pub async fn put(&mut self, key: &[u8], value: &[u8]) -> io::Result<()> { |
| 83 | self.data_block_writer.add(key, value); |
| 84 | |
| 85 | // Only clone key if it changed |
| 86 | match &self.last_key { |
| 87 | Some(last) if last.as_slice() == key => {} |
| 88 | _ => { |
| 89 | self.last_key = Some(key.to_vec()); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if self.data_block_writer.memory() > self.block_size { |
| 94 | self.flush().await?; |
| 95 | } |
| 96 | |
| 97 | self.record_count += 1; |
| 98 | Ok(()) |
| 99 | } |
| 100 | |
| 101 | /// Flush the current data block to output. |
| 102 | pub async fn flush(&mut self) -> io::Result<()> { |