MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Encode

Method Encode

internal/utils/bfs/file_header.go:170–203  ·  view source on GitHub ↗
(hash string)

Source from the content-addressed store, hash-verified

168}
169
170func (this *FileHeader) Encode(hash string) ([]byte, error) {
171 headerJSON, err := json.Marshal(this)
172 if err != nil {
173 return nil, err
174 }
175
176 // we do not compress data which size is less than 100 bytes
177 if len(headerJSON) < 100 {
178 return EncodeMetaBlock(MetaActionNew, hash, append([]byte("json:"), headerJSON...))
179 }
180
181 var buf = utils.SharedBufferPool.Get()
182 defer utils.SharedBufferPool.Put(buf)
183
184 compressor, err := SharedCompressPool.Get(buf)
185 if err != nil {
186 return nil, err
187 }
188
189 _, err = compressor.Write(headerJSON)
190 if err != nil {
191 _ = compressor.Close()
192 SharedCompressPool.Put(compressor)
193 return nil, err
194 }
195
196 err = compressor.Close()
197 SharedCompressPool.Put(compressor)
198 if err != nil {
199 return nil, err
200 }
201
202 return EncodeMetaBlock(MetaActionNew, hash, buf.Bytes())
203}

Callers

nothing calls this directly

Calls 6

EncodeMetaBlockFunction · 0.85
BytesMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected