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

Method Dump

testutil/image_hash.go:103–125  ·  view source on GitHub ↗

Dump writes the hash to a writer Format: [1 byte: type][variable: hash data]

(w io.Writer)

Source from the content-addressed store, hash-verified

101// Dump writes the hash to a writer
102// Format: [1 byte: type][variable: hash data]
103func (h *ImageHash) Dump(w io.Writer) error {
104 // Write type byte
105 if err := binary.Write(w, binary.LittleEndian, h.hashType); err != nil {
106 return fmt.Errorf("failed to write hash type: %w", err)
107 }
108
109 switch h.hashType {
110 case HashTypeSHA256:
111 if _, err := w.Write(h.sha256Hash[:]); err != nil {
112 return fmt.Errorf("failed to write SHA256 hash: %w", err)
113 }
114
115 case HashTypeDct:
116 if err := h.dumpDctHash(w); err != nil {
117 return err
118 }
119
120 default:
121 return fmt.Errorf("unsupported hash type: %d", h.hashType)
122 }
123
124 return nil
125}
126
127// LoadImageHash loads a hash from a reader
128func LoadImageHash(r io.Reader) (*ImageHash, error) {

Callers 3

TestDCT2HashCalcMethod · 0.45
TestSHA256HashCalcMethod · 0.45
ImageMatchesMethod · 0.45

Calls 3

dumpDctHashMethod · 0.95
ErrorfMethod · 0.80
WriteMethod · 0.45

Tested by 2

TestDCT2HashCalcMethod · 0.36
TestSHA256HashCalcMethod · 0.36