MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / Size

Method Size

structure/list.go:735–770  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

733}
734
735func (l *ListStructure) Size(key string) (string, error) {
736 Llen, err := l.LLen(key)
737 if err != nil {
738 return "", err
739 }
740 lRange, err := l.LRange(key, 0, Llen-1)
741 if err != nil {
742 return "", err
743 }
744 var sizeInBytes int
745 for _, v := range lRange {
746 toString, err := interfaceToString(v)
747 if err != nil {
748 return "", err
749 }
750 sizeInBytes += len(toString)
751 }
752 // Convert bytes to corresponding units (KB, MB...)
753 const (
754 KB = 1 << 10
755 MB = 1 << 20
756 GB = 1 << 30
757 )
758
759 var size string
760 switch {
761 case sizeInBytes < KB:
762 size = fmt.Sprintf("%dB", sizeInBytes)
763 case sizeInBytes < MB:
764 size = fmt.Sprintf("%.2fKB", float64(sizeInBytes)/KB)
765 case sizeInBytes < GB:
766 size = fmt.Sprintf("%.2fMB", float64(sizeInBytes)/MB)
767 }
768
769 return size, nil
770}

Callers

nothing calls this directly

Calls 3

LLenMethod · 0.95
LRangeMethod · 0.95
interfaceToStringFunction · 0.85

Tested by

no test coverage detected