MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / File

Method File

pkg/fetch/fs.go:28–50  ·  view source on GitHub ↗
(pathElements ...string)

Source from the content-addressed store, hash-verified

26}
27
28func (f fsFetcher) File(pathElements ...string) ([]byte, error) {
29 if len(pathElements) == 0 {
30 return nil, errFilenameNotSpecified.New()
31 }
32
33 start := time.Now()
34
35 p := filepath.Join(pathElements...)
36 rp, err := realOSPath(f.root, p)
37 if err != nil {
38 return nil, err
39 }
40 content, err := os.ReadFile(rp)
41 if err == nil {
42 f.observeLatency(time.Since(start))
43 return content, nil
44 }
45
46 if os.IsNotExist(err) {
47 return nil, errFileNotFound.WithAttributes("filename", p)
48 }
49 return nil, errCouldNotReadFile.WithCause(err).WithAttributes("filename", p)
50}
51
52// FromFilesystem returns an interface that fetches files from the local filesystem.
53func FromFilesystem(rootElements ...string) Interface {

Callers

nothing calls this directly

Calls 8

realOSPathFunction · 0.85
observeLatencyMethod · 0.80
NewMethod · 0.65
NowMethod · 0.65
JoinMethod · 0.65
ReadFileMethod · 0.65
WithAttributesMethod · 0.45
WithCauseMethod · 0.45

Tested by

no test coverage detected