this repo has no description
1use cid::Cid; 2use std::io::Write; 3 4pub fn write_varint<W: Write>(mut writer: W, mut value: u64) -> std::io::Result<()> { 5 loop { 6 let mut byte = (value & 0x7F) as u8; 7 value >>= 7; 8 if value != 0 { 9 byte |= 0x80; 10 } 11 writer.write_all(&[byte])?; 12 if value == 0 { 13 break; 14 } 15 } 16 Ok(()) 17} 18 19pub fn ld_write<W: Write>(mut writer: W, data: &[u8]) -> std::io::Result<()> { 20 write_varint(&mut writer, data.len() as u64)?; 21 writer.write_all(data)?; 22 Ok(()) 23} 24 25pub fn encode_car_header(root_cid: &Cid) -> Vec<u8> { 26 let header = serde_ipld_dagcbor::to_vec(&serde_json::json!({ 27 "version": 1u64, 28 "roots": [root_cid.to_bytes()] 29 })) 30 .unwrap_or_default(); 31 header 32}