MCPcopy
hub / github.com/perkeep/perkeep / ParseBytes

Function ParseBytes

pkg/blob/ref.go:251–271  ·  view source on GitHub ↗

ParseBytes is like Parse, but parses from a byte slice.

(s []byte)

Source from the content-addressed store, hash-verified

249
250// ParseBytes is like Parse, but parses from a byte slice.
251func ParseBytes(s []byte) (ref Ref, ok bool) {
252 i := bytes.IndexByte(s, '-')
253 if i < 0 {
254 return
255 }
256 name := s[:i] // e.g. "sha1", "sha224"
257 hex := s[i+1:]
258 meta, ok := metaFromBytes(name)
259 if !ok {
260 return parseUnknown(string(name), string(hex))
261 }
262 if len(hex) != meta.size*2 {
263 ok = false
264 return
265 }
266 dt, ok := meta.ctorb(hex)
267 if !ok {
268 return
269 }
270 return Ref{dt}, true
271}
272
273// ParseOrZero parses as a blobref. If s is invalid, a zero Ref is
274// returned which can be tested with the Valid method.

Callers 15

EnumerateBlobsMethod · 0.92
parseMetaRowFunction · 0.92
parseZipMetaRowFunction · 0.92
EnumerateBlobsMethod · 0.92
fixMissingWholeRefMethod · 0.92
kvBlobMeta_bytesFunction · 0.92
initNeededMapsMethod · 0.92
mergeSignerKeyIdRowMethod · 0.92
mergeFileInfoRowMethod · 0.92
mergeFileTimesRowMethod · 0.92
mergeImageSizeRowMethod · 0.92

Calls 2

metaFromBytesFunction · 0.85
parseUnknownFunction · 0.85

Tested by 2

TestParseFunction · 0.68
BenchmarkParseBlobFunction · 0.68