Skip to content

Commit

Permalink
add Append func
Browse files Browse the repository at this point in the history
  • Loading branch information
bughou committed Jul 11, 2020
1 parent b913b31 commit c61d975
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import (
"os"
)

func Append(p string, b []byte) error {
f, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
return err
}
_, err = f.Write(b)
if err2 := f.Close(); err == nil {
err = err2
}
return err
}

func OpenAppend(p string) (*os.File, error) {
return os.OpenFile(p, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
}
Expand Down

0 comments on commit c61d975

Please sign in to comment.