github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/release/github/file.go (about) 1 // Modified from https://github.com/aktau/github-release/blob/master/file.go 2 3 package github 4 5 import ( 6 "fmt" 7 "io" 8 "os" 9 ) 10 11 func getFileSize(f *os.File) (int64, error) { 12 /* first try stat */ 13 off, err := fsizeStat(f) 14 if err != nil { 15 /* if that fails, try seek */ 16 return fsizeSeek(f) 17 } 18 19 return off, nil 20 } 21 22 func fsizeStat(f *os.File) (int64, error) { 23 fi, err := f.Stat() 24 25 if err != nil { 26 return 0, err 27 } 28 29 return fi.Size(), nil 30 } 31 32 func fsizeSeek(f io.Seeker) (int64, error) { 33 off, err := f.Seek(0, 2) 34 if err != nil { 35 return 0, fmt.Errorf("seeking did not work, stdin is not" + 36 "supported yet because github doesn't support chunking" + 37 "requests (and I haven't implemented detecting stdin and" + 38 "buffering yet") 39 } 40 41 _, err = f.Seek(0, 0) 42 if err != nil { 43 return 0, fmt.Errorf("could not seek back in the file") 44 } 45 return off, nil 46 }