readContent opens a named file and read content from it
(rf io.ReaderFrom, name string)
| 148 | |
| 149 | // readContent opens a named file and read content from it |
| 150 | func 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. |
searching dependent graphs…