forked from bazil/bazil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunks.go
34 lines (28 loc) · 845 Bytes
/
chunks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Package chunks implements low-level storage for chunks of data.
package chunks
import (
"fmt"
"bazil.org/bazil/cas"
)
// Chunk is a chunk of data, to be stored in a CAS. A Chunk is assumed
// to be small enough to fit fully in memory in a single contiguous
// range of bytes.
type Chunk struct {
Type string
Level uint8
Buf []byte
}
func (c *Chunk) String() string {
return fmt.Sprintf("Chunk{%q@%d %x}", c.Type, c.Level, c.Buf)
}
// Store is a low-level CAS store that stores limited size chunks. It
// is not meant to store files directly.
type Store interface {
// Get a chunk from the chunk store.
//
// The returned Chunk is considered read-only and must not be
// modified.
Get(key cas.Key, type_ string, level uint8) (*Chunk, error)
// Add a chunk to the chunk store.
Add(chunk *Chunk) (key cas.Key, err error)
}