mirror of https://github.com/schollz/croc.git
Simplified FileSize function
This commit is contained in:
parent
3bb1c015c8
commit
b10d8a075b
8
utils.go
8
utils.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue