File: sif.go

package info (click to toggle)
singularity-container 4.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,672 kB
  • sloc: asm: 3,857; sh: 2,125; ansic: 1,677; awk: 414; makefile: 110; python: 99
file content (47 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
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
// Copyright 2023 Sylabs Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

package sif

import (
	"io"

	v1 "github.com/google/go-containerregistry/pkg/v1"
	"github.com/sylabs/sif/v2/pkg/sif"
)

// fileImage represents a Singularity Image Format (SIF) file containing OCI artifacts.
type fileImage struct {
	*sif.FileImage
}

// Blob returns a ReadCloser that reads the blob with the supplied digest.
func (f *fileImage) Blob(h v1.Hash) (io.ReadCloser, error) {
	d, err := f.GetDescriptor(sif.WithOCIBlobDigest(h))
	if err != nil {
		return nil, err
	}

	return io.NopCloser(d.GetReader()), nil
}

// Bytes returns the bytes of the blob with the supplied digest.
func (f *fileImage) Bytes(h v1.Hash) ([]byte, error) {
	d, err := f.GetDescriptor(sif.WithOCIBlobDigest(h))
	if err != nil {
		return nil, err
	}

	return d.GetData()
}

// Offset returns the offset within the SIF image of the blob with the supplied digest.
func (f *fileImage) Offset(h v1.Hash) (int64, error) {
	d, err := f.GetDescriptor(sif.WithOCIBlobDigest(h))
	if err != nil {
		return 0, err
	}

	return d.Offset(), nil
}