EncodedObjectSize implements storage.Storer.
(h plumbing.Hash)
| 89 | |
| 90 | // EncodedObjectSize implements storage.Storer. |
| 91 | func (s *Storage) EncodedObjectSize(h plumbing.Hash) (int64, error) { |
| 92 | pattern := withNamespace(s.namespacePrefix, objectPrefix, fmt.Sprintf("*:%s", h.String())) |
| 93 | var cursor uint64 |
| 94 | var err error |
| 95 | for { |
| 96 | // Scan for keys that match the hash pattern |
| 97 | var keys []string |
| 98 | keys, cursor, err = s.client.Scan(ctx, cursor, pattern, 1).Result() |
| 99 | if err != nil { |
| 100 | return 0, err |
| 101 | } |
| 102 | if len(keys) > 0 { |
| 103 | // Use STRLEN to get the size of the object stored at the found key |
| 104 | size, err := s.client.StrLen(ctx, keys[0]).Result() |
| 105 | if err != nil { |
| 106 | return 0, err |
| 107 | } |
| 108 | return size, nil |
| 109 | } |
| 110 | if cursor == 0 { // No more keys to scan |
| 111 | break |
| 112 | } |
| 113 | } |
| 114 | return 0, plumbing.ErrObjectNotFound |
| 115 | } |
| 116 | |
| 117 | func (s *Storage) HasEncodedObject(h plumbing.Hash) error { |
| 118 | pattern := withNamespace(s.namespacePrefix, objectPrefix, fmt.Sprintf("*:%s", h.String())) |
nothing calls this directly
no test coverage detected