MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / write

Method write

car/src/sync/writer.rs:30–54  ·  view source on GitHub ↗

Writes header and stream of data to writer in Car format.

(&mut self, cid: Cid, data: T)

Source from the content-addressed store, hash-verified

28
29 /// Writes header and stream of data to writer in Car format.
30 pub fn write<T>(&mut self, cid: Cid, data: T) -> Result<(), Error>
31 where
32 T: AsRef<[u8]>,
33 {
34 if !self.is_header_written {
35 // Write header bytes
36 let header_bytes = self.header.encode()?;
37 self.writer.write_varint(header_bytes.len())?;
38 self.writer.write_all(&header_bytes)?;
39 self.is_header_written = true;
40 }
41
42 // Write the given block.
43 self.cid_buffer.clear();
44 cid.write_bytes(&mut self.cid_buffer).expect("vec write");
45
46 let data = data.as_ref();
47 let len = self.cid_buffer.len() + data.len();
48
49 self.writer.write_varint(len)?;
50 self.writer.write_all(&self.cid_buffer)?;
51 self.writer.write_all(data)?;
52
53 Ok(())
54 }
55
56 /// Finishes writing, including flushing and returns the writer.
57 pub fn finish(mut self) -> Result<W, Error> {

Callers 1

car_write_readFunction · 0.45

Calls 6

write_allMethod · 0.80
expectMethod · 0.80
encodeMethod · 0.45
lenMethod · 0.45
clearMethod · 0.45
as_refMethod · 0.45

Tested by 1

car_write_readFunction · 0.36