Skip to content

Commit

Permalink
Merge pull request #26 from containers/add-accessors
Browse files Browse the repository at this point in the history
Make fields non-public with readonly accessors
  • Loading branch information
ariel-miculas authored Sep 30, 2024
2 parents a5f5bfe + 961c9df commit 0738d7e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ impl From<openssl::error::ErrorStack> for Error {
#[derive(Debug)]
pub struct Blob {
/// SHA-256 digest
pub sha256: oci_image::Sha256Digest,
sha256: oci_image::Sha256Digest,
/// Size
pub size: u64,
size: u64,
}

impl Blob {
Expand All @@ -95,6 +95,11 @@ impl Blob {
.digest(self.sha256.clone())
.size(self.size)
}

/// Return the size of this blob
pub fn size(&self) -> u64 {
self.size
}
}

/// Completed layer metadata
Expand Down Expand Up @@ -123,9 +128,9 @@ impl Layer {
/// Create an OCI blob.
pub struct BlobWriter<'a> {
/// Compute checksum
pub hash: Hasher,
hash: Hasher,
/// Target file
pub target: Option<cap_tempfile::TempFile<'a>>,
target: Option<cap_tempfile::TempFile<'a>>,
size: u64,
}

Expand All @@ -149,8 +154,8 @@ pub struct ZstdLayerWriter<'a>(Sha256Writer<zstd::Encoder<'static, BlobWriter<'a
/// An opened OCI directory.
pub struct OciDir {
/// The underlying directory.
pub dir: Dir,
pub blobs_dir: Dir,
dir: Dir,
blobs_dir: Dir,
}

/// Write a serializable data (JSON) as an OCI blob
Expand Down Expand Up @@ -242,6 +247,16 @@ impl OciDir {
Ok(Self { dir, blobs_dir })
}

/// Return the underlying directory.
pub fn dir(&self) -> &Dir {
&self.dir
}

/// Return the underlying directory for blobs.
pub fn blobs_dir(&self) -> &Dir {
&self.blobs_dir
}

/// Write a serializable data (JSON) as an OCI blob
pub fn write_json_blob<S: serde::Serialize>(
&self,
Expand Down

0 comments on commit 0738d7e

Please sign in to comment.