Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WriteFile and OpenReadFile variables in buildtools/file API. #1238

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import (
// ReadFile can be updated from the caller to change the API
// for reading a file.
var ReadFile = readFile
// WriteFile can be updated from the caller to change the API
// for writing a file.
var WriteFile = writeFile
// OpenReadFile can be updated from the caller to change the API
// for opening a file.
var OpenReadFile = openReadFile

// readFile is like ioutil.ReadFile.
func readFile(name string) ([]byte, os.FileInfo, error) {
Expand All @@ -39,13 +45,13 @@ func readFile(name string) ([]byte, os.FileInfo, error) {
return data, fi, err
}

// WriteFile is like ioutil.WriteFile
func WriteFile(name string, data []byte) error {
// writeFile is like ioutil.WriteFile.
func writeFile(name string, data []byte) error {
return ioutil.WriteFile(name, data, 0644)
}

// OpenReadFile is like os.Open.
func OpenReadFile(name string) io.ReadCloser {
// openReadFile is like os.Open.
func openReadFile(name string) io.ReadCloser {
f, err := os.Open(name)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not open %s\n", name)
Expand Down