MCPcopy Create free account
hub / github.com/containers/image / NewReaderFromFile

Function NewReaderFromFile

docker/internal/tarfile/reader.go:30–52  ·  view source on GitHub ↗

NewReaderFromFile returns a Reader for the specified path. The caller should call .Close() on the returned archive when done.

(sys *types.SystemContext, path string)

Source from the content-addressed store, hash-verified

28// NewReaderFromFile returns a Reader for the specified path.
29// The caller should call .Close() on the returned archive when done.
30func NewReaderFromFile(sys *types.SystemContext, path string) (*Reader, error) {
31 file, err := os.Open(path)
32 if err != nil {
33 return nil, fmt.Errorf("opening file %q: %w", path, err)
34 }
35 defer file.Close()
36
37 // If the file is seekable and already not compressed we can just return the file itself
38 // as a source. Otherwise we pass the stream to NewReaderFromStream.
39 var stream io.Reader = file
40 if _, err := file.Seek(0, io.SeekCurrent); err == nil { // seeking is possible
41 decompressed, isCompressed, err := compression.AutoDecompress(file)
42 if err != nil {
43 return nil, fmt.Errorf("detecting compression for file %q: %w", path, err)
44 }
45 defer decompressed.Close()
46 stream = decompressed
47 if !isCompressed {
48 return newReader(path, false)
49 }
50 }
51 return NewReaderFromStream(sys, stream)
52}
53
54// NewReaderFromStream returns a Reader for the specified inputStream,
55// which can be either compressed or uncompressed. The caller can close the

Callers 2

NewReaderFunction · 0.92
newImageSourceFunction · 0.92

Calls 5

AutoDecompressFunction · 0.92
newReaderFunction · 0.85
NewReaderFromStreamFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…