fileutils.go 487 B

123456789101112131415161718192021222324252627
  1. package megauploader
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type fileIncrement struct {
  7. pre string
  8. post string
  9. }
  10. func (fi fileIncrement) Increment(i int) string {
  11. if i == 0 {
  12. return fmt.Sprintf("%s%s", fi.pre, fi.post)
  13. }
  14. return fmt.Sprintf("%s-%d%s", fi.pre, i, fi.post)
  15. }
  16. func newFileIncrement(fn string) fileIncrement {
  17. idx := strings.Index(fn, ".")
  18. if idx != -1 {
  19. return fileIncrement{pre: fn[0:idx], post: fn[idx:]}
  20. } else {
  21. return fileIncrement{pre: fn[0:], post: ""}
  22. }
  23. }