Simplified FileSize function

This commit is contained in:
h3yEllex 2017-10-25 15:03:36 +03:00
parent 3bb1c015c8
commit b10d8a075b
2 changed files with 3 additions and 9 deletions

View File

@ -163,13 +163,7 @@ func HashFile(filename string) (hash string, err error) {
// FileSize returns the size of a file
func FileSize(filename string) (int, error) {
f, err := os.Open(filename)
if err != nil {
return -1, err
}
defer f.Close()
fi, err := f.Stat()
fi, err := os.Stat(filename)
if err != nil {
return -1, err
}

View File

@ -26,8 +26,8 @@ func TestFileSize(t *testing.T) {
if err == nil {
t.Error("should return an error")
}
if s > 0 {
t.Errorf("size should be 0, got: %d", s)
if s != -1 {
t.Errorf("size should be -1, got: %d", s)
}
})
}