Skip to content

Commit

Permalink
change hashing algorithm - add new folder level
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Mar 8, 2018
1 parent 3dc7f53 commit 271c5d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Binary file added favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions pkg/object/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ func Parse(url *url.URL, mortConfig *config.Config, obj *FileObject) error {
func hashKey(h hash.Hash64, suffix string) string {
hashB := []byte(strconv.FormatUint(uint64(h.Sum64()), 16))
buf := bufPool.Get().(*bytes.Buffer)
safePath := strings.Replace(suffix, "/", "-", -1)
sliceRange := 3

if l := len(safePath); l < 3 {
sliceRange = l
}

buf.Reset()
buf.WriteByte('/')
buf.Write(hashB[0:3])
buf.WriteByte('/')
buf.Write(hashB)
buf.WriteString(safePath[0:sliceRange])
buf.WriteByte('/')
buf.WriteString(safePath)
buf.WriteByte('-')
buf.WriteString(strings.Replace(suffix, "/", "-", -1))
buf.Write(hashB)
defer bufPool.Put(buf)
return buf.String()
}
Expand Down

0 comments on commit 271c5d7

Please sign in to comment.