Debian Codegraph @

nullchunk.go

raw
1 package desync
2
3 // NullChunk is used in places where it's common to see requests for chunks
4 // containing only 0-bytes. When a chunked file has large areas of 0-bytes,
5 // the chunking algorithm does not produce split boundaries, which results
6 // in many chunks of 0-bytes of size MAX (max chunk size). The NullChunk can be
7 // used to make requesting this kind of chunk more efficient by serving it
8 // from memory, rather than request it from disk or network and decompress
9 // it repeatedly.
10 type NullChunk struct {
11 Data []byte
12 ID ChunkID
13 }
14
15 // NewNullChunk returns an initialized chunk consisting of 0-bytes of 'size'
16 // which must match the max size used in the index to be effective
17 func NewNullChunk(size uint64) *NullChunk {
18 b := make([]byte, int(size))
19 return &NullChunk{
20 Data: b,
21 ID: Digest.Sum(b),
22 }
23 }