Skip to content

Instantly share code, notes, and snippets.

@zelig

zelig/chunk.go Secret

Created January 22, 2018 11:17
Show Gist options
  • Save zelig/e6f4234fc9af9a5b3aca4ad9339a45a7 to your computer and use it in GitHub Desktop.
Save zelig/e6f4234fc9af9a5b3aca4ad9339a45a7 to your computer and use it in GitHub Desktop.
new chunk interface
// Split(ctx context.Context, data io.Reader, put func([]byte) Chunk) (Key, <-chan struct{}, err)
// Join(hash []byte, get func(Key)) LazySectionReader
// LazySectionReader should implement the WriterTo interface
type Context {
Done() <-chan struct{}
Err() error
}
const (
Created int = iota
Fetching
Available
Unavailable
Stored
Unstoreable
)
type Chunk interface {
Data() Data
Addr() Key
Ready() Context
Stored() Context
}
type ChunkFetcher interface {
Fetch(ctx context.Context)
}
type Data interface {
Span() int64
Length() int
Bytes() []byte
}
type SegmentWriter interface {
Write(int, []byte)
}
func IsAvailable(c Chunk) (bool, err){
ctx := c.Ready()
if ctx == nil {
return true, nil
}
select {
case ctx.Done():
return true, ctx.Err()
default:
return false, nil
}
}
func IsStored(c Chunk) (bool, err) {
ctx := c.Store()
if ctx == nil {
return true, nil
}
select {
case ctx.Done():
return true, ctx.Err()
default:
return false, nil
}
}
func State(c Chunk) int {
}
- created
- fetching
- ready
- unavailable
- stored
- not-stored
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment