MCPcopy
hub / github.com/gofiber/fiber / readContent

Function readContent

helpers.go:150–166  ·  view source on GitHub ↗

readContent opens a named file and read content from it

(rf io.ReaderFrom, name string)

Source from the content-addressed store, hash-verified

148
149// readContent opens a named file and read content from it
150func readContent(rf io.ReaderFrom, name string) (int64, error) {
151 // Read file
152 f, err := os.Open(filepath.Clean(name))
153 if err != nil {
154 return 0, fmt.Errorf("failed to open: %w", err)
155 }
156 defer func() {
157 if err = f.Close(); err != nil {
158 log.Errorf("Error closing file: %s", err)
159 }
160 }()
161 n, readErr := rf.ReadFrom(f)
162 if readErr != nil {
163 return n, fmt.Errorf("failed to read: %w", readErr)
164 }
165 return n, nil
166}
167
168// quoteString escapes special characters using percent-encoding.
169// Non-ASCII bytes are encoded as well so the result is always ASCII.

Callers 2

RenderMethod · 0.85

Calls 4

ErrorfFunction · 0.92
ErrorfMethod · 0.65
CloseMethod · 0.65
ReadFromMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…