-
-
Save zelig/e6f4234fc9af9a5b3aca4ad9339a45a7 to your computer and use it in GitHub Desktop.
new chunk interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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