(buffer: &[u8])
| 16 | } |
| 17 | |
| 18 | pub fn decode(buffer: &[u8]) -> Result<Self, Error> { |
| 19 | let header: CarHeaderV1 = |
| 20 | serde_ipld_dagcbor::from_slice(buffer).map_err(|e| Error::Parsing(e.to_string()))?; |
| 21 | |
| 22 | if header.roots.is_empty() { |
| 23 | return Err(Error::Parsing("empty CAR file".to_owned())); |
| 24 | } |
| 25 | |
| 26 | if header.version != 1 { |
| 27 | return Err(Error::InvalidFile( |
| 28 | "Only CAR file version 1 is supported".to_string(), |
| 29 | )); |
| 30 | } |
| 31 | |
| 32 | Ok(CarHeader::V1(header)) |
| 33 | } |
| 34 | |
| 35 | pub fn encode(&self) -> Result<Vec<u8>, Error> { |
| 36 | match self { |