hypha: implement OCI image layer spec

This commit is contained in:
Alex Zenla
2024-01-20 02:41:49 -08:00
parent 4b664c0616
commit 2567a93512
3 changed files with 183 additions and 36 deletions

View File

@ -1,6 +1,8 @@
use crate::error::{HyphaError, Result};
use oci_spec::image::{Arch, Descriptor, ImageIndex, ImageManifest, MediaType, Os, ToDockerV2S2};
use std::io::Read;
use std::io::copy;
use std::io::{Read, Write};
use std::ops::DerefMut;
use ureq::{Agent, Request, Response};
use url::Url;
@ -31,6 +33,20 @@ impl RegistryClient {
Ok(buffer)
}
pub fn write_blob(
&mut self,
name: &str,
descriptor: &Descriptor,
dest: &mut dyn Write,
) -> Result<u64> {
let url = self
.url
.join(&format!("/v2/{}/blobs/{}", name, descriptor.digest()))?;
let response = self.call(self.agent.get(url.as_str()))?;
let mut reader = response.into_reader();
Ok(copy(reader.deref_mut(), dest)?)
}
pub fn get_manifest(&mut self, name: &str, reference: &str) -> Result<ImageManifest> {
let url = self
.url