MCPcopy Index your code
hub / github.com/devspace-sh/devspace / ReadFile

Function ReadFile

pkg/util/fsutil/filesystem.go:38–64  ·  view source on GitHub ↗

ReadFile reads a file with a given limit

(path string, limit int64)

Source from the content-addressed store, hash-verified

36
37// ReadFile reads a file with a given limit
38func ReadFile(path string, limit int64) ([]byte, error) {
39 if limit <= 0 {
40 return os.ReadFile(path)
41 }
42
43 f, err := os.Open(path)
44 if err != nil {
45 return nil, err
46 }
47 defer f.Close()
48
49 st, err := f.Stat()
50 if err != nil {
51 return nil, err
52 }
53
54 size := st.Size()
55 if limit > 0 && size > limit {
56 size = limit
57 }
58
59 buf := bytes.NewBuffer(nil)
60 buf.Grow(int(size))
61 _, err = io.Copy(buf, io.LimitReader(f, limit))
62
63 return buf.Bytes(), err
64}
65
66// Copy copies a file to a destination path
67func Copy(sourcePath string, targetPath string, overwrite bool) error {

Callers 3

TestLanguageHandlerFunction · 0.92
TestWriteReadFileFunction · 0.85
TestCopyFunction · 0.85

Calls 3

CloseMethod · 0.65
CopyMethod · 0.65
SizeMethod · 0.45

Tested by 3

TestLanguageHandlerFunction · 0.74
TestWriteReadFileFunction · 0.68
TestCopyFunction · 0.68