snix_store/nar/
mod.rs

1use snix_castore::B3Digest;
2use tonic::async_trait;
3
4mod hashing_reader;
5mod import;
6mod renderer;
7pub mod seekable;
8pub use import::{NarIngestionError, ingest_nar, ingest_nar_and_hash};
9pub use renderer::SimpleRenderer;
10pub use renderer::calculate_size_and_sha256;
11pub use renderer::write_nar;
12use snix_castore::Node;
13
14#[async_trait]
15pub trait NarCalculationService: Send + Sync {
16    /// Return the nar size and nar sha256 digest for a given root node.
17    /// This can be used to calculate NAR-based output paths.
18    async fn calculate_nar(&self, root_node: &Node)
19    -> Result<(u64, [u8; 32]), snix_castore::Error>;
20}
21
22#[async_trait]
23impl<A> NarCalculationService for A
24where
25    A: AsRef<dyn NarCalculationService> + Send + Sync,
26{
27    async fn calculate_nar(
28        &self,
29        root_node: &Node,
30    ) -> Result<(u64, [u8; 32]), snix_castore::Error> {
31        self.as_ref().calculate_nar(root_node).await
32    }
33}
34
35/// Errors that can encounter while rendering NARs.
36#[derive(Debug, thiserror::Error)]
37pub enum RenderError {
38    #[error("failure talking to a backing store client: {0}")]
39    StoreError(#[source] std::io::Error),
40
41    #[error("unable to find directory {0}, referred from {1:?}")]
42    DirectoryNotFound(B3Digest, bytes::Bytes),
43
44    #[error("unable to find blob {0}, referred from {1:?}")]
45    BlobNotFound(B3Digest, bytes::Bytes),
46
47    #[error(
48        "unexpected size in metadata for blob {0}, referred from {1:?} returned, expected {2}, got {3}"
49    )]
50    UnexpectedBlobMeta(B3Digest, bytes::Bytes, u32, u32),
51
52    #[error("failure using the NAR writer: {0}")]
53    NARWriterError(std::io::Error),
54}