MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / decodeHeader

Function decodeHeader

cache/filesystem_cache.go:138–165  ·  view source on GitHub ↗

decodeHeader decodes header from raw byte stream. Data is encoded as follows: length(contentType)|contentType|length(contentEncoding)|contentEncoding|length(contentLength)|contentLength|cachedData

(reader io.Reader)

Source from the content-addressed store, hash-verified

136// decodeHeader decodes header from raw byte stream. Data is encoded as follows:
137// length(contentType)|contentType|length(contentEncoding)|contentEncoding|length(contentLength)|contentLength|cachedData
138func decodeHeader(reader io.Reader) (*ContentMetadata, error) {
139 contentType, err := readHeader(reader)
140 if err != nil {
141 return nil, fmt.Errorf("cannot read Content-Type from provided reader: %w", err)
142 }
143
144 contentEncoding, err := readHeader(reader)
145 if err != nil {
146 return nil, fmt.Errorf("cannot read Content-Encoding from provided reader: %w", err)
147 }
148
149 contentLengthStr, err := readHeader(reader)
150 if err != nil {
151 return nil, fmt.Errorf("cannot read Content-Encoding from provided reader: %w", err)
152 }
153
154 contentLength, err := strconv.Atoi(contentLengthStr)
155 if err != nil {
156 log.Errorf("found corrupted content length %s", err)
157 contentLength = 0
158 }
159
160 return &ContentMetadata{
161 Length: int64(contentLength),
162 Type: contentType,
163 Encoding: contentEncoding,
164 }, nil
165}
166
167func (f *fileSystemCache) Put(r io.Reader, contentMetadata ContentMetadata, key *Key) (time.Duration, error) {
168 fp := key.filePath(f.dir)

Callers 1

GetMethod · 0.85

Calls 2

ErrorfFunction · 0.92
readHeaderFunction · 0.85

Tested by

no test coverage detected