This repository was archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathatom.go
More file actions
53 lines (44 loc) · 1.4 KB
/
atom.go
File metadata and controls
53 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package atomfs
import (
"io"
"github.com/anuvu/atomfs/types"
"github.com/opencontainers/umoci/oci/casext"
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
func (atomfs *Instance) GetAtoms() ([]types.Atom, error) {
return atomfs.db.GetAtoms()
}
func (atomfs *Instance) CreateAtom(name string, atomType types.AtomType, content io.Reader) (types.Atom, error) {
return atomfs.db.CreateAtom(name, atomType, content)
}
func (atomfs *Instance) CreateAtomFromOCIBlob(blob *casext.Blob) (types.Atom, error) {
atomType := types.TarAtom
switch blob.Descriptor.MediaType {
case ispec.MediaTypeImageLayer:
fallthrough
case ispec.MediaTypeImageLayerGzip:
fallthrough
case ispec.MediaTypeImageLayerNonDistributable:
fallthrough
case ispec.MediaTypeImageLayerNonDistributableGzip:
atomType = types.TarAtom
// stolen from stacker:base.go
case "application/vnd.oci.image.layer.squashfs":
atomType = types.SquashfsAtom
default:
return types.Atom{}, errors.Errorf("unknown media type: %s", blob.Descriptor.MediaType)
}
return atomfs.db.CreateAtom(blob.Descriptor.Digest.Encoded(), atomType, blob.Data.(io.Reader))
}
func (atomfs *Instance) GetAtomsByHash() (map[string]types.Atom, error) {
atomsList, err := atomfs.GetAtoms()
if err != nil {
return nil, err
}
atoms := map[string]types.Atom{}
for _, atom := range atomsList {
atoms[atom.Hash] = atom
}
return atoms, nil
}