...

Source file src/edge-infra.dev/pkg/f8n/warehouse/oci/cache/layer.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/oci/cache

     1  package cache
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  
     7  	"edge-infra.dev/pkg/f8n/warehouse/oci/layer"
     8  )
     9  
    10  // cachingLayer wraps access to v1.Layer with a [Cache]. Implements v1.Layer
    11  type cachingLayer struct {
    12  	layer.Layer
    13  	cache *LazyCache
    14  	data  []byte
    15  }
    16  
    17  // Layer returns a new v1.Layer whose contents will be read from a [Cache] if found, falling
    18  // back to fetching from remote if not found
    19  func Layer(l layer.Layer, c *LazyCache, data []byte) layer.Layer {
    20  	return &cachingLayer{
    21  		Layer: l,
    22  		cache: c,
    23  		data:  data,
    24  	}
    25  }
    26  
    27  func (c *cachingLayer) Compressed() (io.ReadCloser, error) {
    28  	// TODO(dk185217): make sense of compressed vs uncompressed / digest vs diffid
    29  	return io.NopCloser(bytes.NewReader(c.data)), nil
    30  }
    31  
    32  func (c *cachingLayer) Uncompressed() (io.ReadCloser, error) {
    33  	return io.NopCloser(bytes.NewReader(c.data)), nil
    34  }
    35  

View as plain text