MCPcopy Create free account
hub / github.com/prometheus/common / Open

Method Open

assets/embed_gzip.go:37–61  ·  view source on GitHub ↗

Open implements the fs.FS interface.

(path string)

Source from the content-addressed store, hash-verified

35
36// Open implements the fs.FS interface.
37func (compressed FileSystem) Open(path string) (fs.File, error) {
38 // If we have the file in our embed FS, just return that as it could be a dir.
39 var f fs.File
40 if f, err := compressed.embed.Open(path); err == nil {
41 return f, nil
42 }
43
44 f, err := compressed.embed.Open(path + gzipSuffix)
45 if err != nil {
46 return f, err
47 }
48 // Read the decompressed content into a buffer.
49 gr, err := gzip.NewReader(f)
50 if err != nil {
51 return f, err
52 }
53 defer gr.Close()
54
55 c, err := io.ReadAll(gr)
56 if err != nil {
57 return f, err
58 }
59 // Wrap everything in our custom File.
60 return &File{file: f, content: c}, nil
61}
62
63type File struct {
64 // The underlying file.

Callers 1

TestFSFunction · 0.45

Calls 1

CloseMethod · 0.65

Tested by 1

TestFSFunction · 0.36