Skip to content

Commit 3135f6a

Browse files
Add documentation for writer functions
Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 87b7796 commit 3135f6a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/zstd_encoder.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ impl ZstdWriter {
198198
Ok(self.writer.write_all(data)?)
199199
}
200200

201+
/// Writes all the data in `inline_content`, updating the internal SHA
201202
pub(crate) fn flush_inline(&mut self, inline_content: &Vec<u8>) -> Result<()> {
202203
if inline_content.is_empty() {
203204
return Ok(());
@@ -212,6 +213,8 @@ impl ZstdWriter {
212213
Ok(())
213214
}
214215

216+
/// Keeps popping from the heap until it reaches the message with the largest seq_num, n,
217+
/// given we have every message with seq_num < n
215218
fn write_message(&mut self) -> Result<()> {
216219
loop {
217220
// Gotta keep lifetime of the destructring inside the loop
@@ -234,9 +237,7 @@ impl ZstdWriter {
234237
sha256.update(data.0.object_data.external_data);
235238
}
236239

237-
if let Err(e) = self.write_fragment(0, &data.0.digest) {
238-
println!("write_fragment err while writing external content: {e:?}");
239-
}
240+
self.write_fragment(0, &data.0.digest)?;
240241
}
241242

242243
let final_msg = self.get_state_mut().final_message.take();
@@ -281,6 +282,7 @@ impl ZstdWriter {
281282
return Ok(sha);
282283
}
283284

285+
/// Calls `finish` on the internal writer
284286
pub(crate) fn finish(self) -> io::Result<Vec<u8>> {
285287
self.writer.finish()
286288
}
@@ -310,7 +312,8 @@ impl ZstdWriter {
310312
}
311313

312314
// Cannot `take` ownership of self, as we'll need it later
313-
// returns whether finished or not
315+
//
316+
/// Returns whether we have finished writing all the data or not
314317
fn handle_received_data(&mut self, data: WriterMessages) -> Result<bool> {
315318
match data {
316319
WriterMessages::WriteData(recv_data) => {
@@ -321,11 +324,6 @@ impl ZstdWriter {
321324
let object_path = Repository::format_object_path(&recv_data.digest);
322325
self.repository.ensure_symlink(&stream_path, &object_path)?;
323326

324-
// if let Some(name) = reference {
325-
// let reference_path = format!("streams/refs/{name}");
326-
// self.symlink(&reference_path, &stream_path)?;
327-
// }
328-
329327
if let Err(e) = self
330328
.get_state()
331329
.final_result_sender

0 commit comments

Comments
 (0)