2013-12-19 16:01:34 -07:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
type TestModel struct {
|
|
|
|
data []byte
|
2014-02-13 04:41:25 -07:00
|
|
|
repo string
|
2013-12-19 16:01:34 -07:00
|
|
|
name string
|
2014-01-09 08:35:49 -07:00
|
|
|
offset int64
|
2014-02-23 05:58:10 -07:00
|
|
|
size int
|
2013-12-19 16:01:34 -07:00
|
|
|
closed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestModel) Index(nodeID string, files []FileInfo) {
|
|
|
|
}
|
|
|
|
|
2013-12-28 08:30:02 -07:00
|
|
|
func (t *TestModel) IndexUpdate(nodeID string, files []FileInfo) {
|
|
|
|
}
|
|
|
|
|
2014-02-23 05:58:10 -07:00
|
|
|
func (t *TestModel) Request(nodeID, repo, name string, offset int64, size int) ([]byte, error) {
|
2014-02-13 04:41:25 -07:00
|
|
|
t.repo = repo
|
2013-12-19 16:01:34 -07:00
|
|
|
t.name = name
|
|
|
|
t.offset = offset
|
|
|
|
t.size = size
|
|
|
|
return t.data, nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 19:21:57 -07:00
|
|
|
func (t *TestModel) Close(nodeID string, err error) {
|
2013-12-19 16:01:34 -07:00
|
|
|
t.closed = true
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrPipe struct {
|
|
|
|
io.PipeWriter
|
|
|
|
written int
|
|
|
|
max int
|
|
|
|
err error
|
|
|
|
closed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ErrPipe) Write(data []byte) (int, error) {
|
|
|
|
if e.closed {
|
|
|
|
return 0, e.err
|
|
|
|
}
|
|
|
|
if e.written+len(data) > e.max {
|
|
|
|
n, _ := e.PipeWriter.Write(data[:e.max-e.written])
|
|
|
|
e.PipeWriter.CloseWithError(e.err)
|
|
|
|
e.closed = true
|
|
|
|
return n, e.err
|
|
|
|
} else {
|
|
|
|
return e.PipeWriter.Write(data)
|
|
|
|
}
|
|
|
|
}
|