pub mod tar_file;
use crate::filesystem::FileSystem;
use crate::util::DigestPre;
use anyhow::{anyhow, Context, Result};
use oci_distribution::client::ImageLayer;
pub static LAYER_MEDIA_TYPE: &str = "application/vnd.oci.image.layer.v1.tar";
pub struct LayerAndData {
pub data: Vec<u8>,
pub media_type: String,
}
impl LayerAndData {
pub fn load(desc_digest: &String, media_type: String) -> Result<Self> {
let layer_digest = desc_digest.get_digest()?;
let layer_path = FileSystem.layer_blobs()?.join(&layer_digest);
let data = std::fs::read(&layer_path).context(anyhow!("加载{:?}失败", layer_path))?;
Ok(Self {
data,
media_type, })
}
}
impl From<LayerAndData> for ImageLayer {
fn from(lad: LayerAndData) -> Self {
let LayerAndData { data, media_type } = lad;
Self {
data,
media_type,
annotations: None,
}
}
}