MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / LoadImageHash

Function LoadImageHash

testutil/image_hash.go:128–152  ·  view source on GitHub ↗

LoadImageHash loads a hash from a reader

(r io.Reader)

Source from the content-addressed store, hash-verified

126
127// LoadImageHash loads a hash from a reader
128func LoadImageHash(r io.Reader) (*ImageHash, error) {
129 h := &ImageHash{}
130
131 // Read type byte
132 if err := binary.Read(r, binary.LittleEndian, &h.hashType); err != nil {
133 return nil, fmt.Errorf("failed to read hash type: %w", err)
134 }
135
136 switch h.hashType {
137 case HashTypeSHA256:
138 if _, err := io.ReadFull(r, h.sha256Hash[:]); err != nil {
139 return nil, fmt.Errorf("failed to read SHA256 hash: %w", err)
140 }
141
142 case HashTypeDct:
143 if err := h.loadDctHash(r); err != nil {
144 return nil, err
145 }
146
147 default:
148 return nil, fmt.Errorf("unsupported hash type: %d", h.hashType)
149 }
150
151 return h, nil
152}
153
154// String returns a string representation of the hash
155func (h *ImageHash) String() string {

Callers 3

TestDCT2HashCalcMethod · 0.92
TestSHA256HashCalcMethod · 0.92
ImageMatchesMethod · 0.85

Calls 3

loadDctHashMethod · 0.95
ErrorfMethod · 0.80
ReadMethod · 0.45

Tested by 2

TestDCT2HashCalcMethod · 0.74
TestSHA256HashCalcMethod · 0.74