diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-11-25 20:18:44 -0500 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-11-25 20:20:37 -0500 |
commit | 43ea9acb421baa6f3379af9ae4508dfb4bf339ab (patch) | |
tree | e75f28f4fb226b427078c7d880aebb7726ee2f02 /file/file.go | |
parent | c4b7b46835ae6118ffaa7aa0b234211b3fdc28cc (diff) |
file: add `ReadFile`
Diffstat (limited to 'file/file.go')
-rw-r--r-- | file/file.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/file/file.go b/file/file.go index 4267b10..9bb974d 100644 --- a/file/file.go +++ b/file/file.go @@ -24,6 +24,16 @@ func Read(f *os.File) ([]byte, error) { return bs, nil } +func ReadFile(path string) ([]byte, error) { + f, err := os.Open(path) + if err != nil { + return []byte{}, err + } + defer f.Close() + + return Read(f) +} + func Write(f *os.File, content []byte) error { n, err := f.Write(content) if n != len(content) { |