blob: 2224d7d5ee1cf724d4bf6a2064c0d2376dc80110 [file] [log] [blame]
package main
import (
"fmt"
"os"
)
func exists(filename string) bool {
f, err := os.Open(filename)
if err != nil {
return false
}
f.Close()
return true
}
func readFile(filename string) ([]byte, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
return nil, err
}
buf := make([]byte, fi.Size())
n, err := f.Read(buf)
if err != nil {
return nil, err
}
if n != len(buf) {
return nil, fmt.Errorf("Unexpected file size: %d vs %d", n, len(buf))
}
return buf, nil
}