2013-12-19 23:01:34 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
type TestModel struct {
|
|
|
|
data []byte
|
2014-02-13 11:41:25 +00:00
|
|
|
repo string
|
2013-12-19 23:01:34 +00:00
|
|
|
name string
|
2014-01-09 15:35:49 +00:00
|
|
|
offset int64
|
2014-02-23 12:58:10 +00:00
|
|
|
size int
|
2013-12-19 23:01:34 +00:00
|
|
|
closed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestModel) Index(nodeID string, files []FileInfo) {
|
|
|
|
}
|
|
|
|
|
2013-12-28 15:30:02 +00:00
|
|
|
func (t *TestModel) IndexUpdate(nodeID string, files []FileInfo) {
|
|
|
|
}
|
|
|
|
|
2014-02-23 12:58:10 +00:00
|
|
|
func (t *TestModel) Request(nodeID, repo, name string, offset int64, size int) ([]byte, error) {
|
2014-02-13 11:41:25 +00:00
|
|
|
t.repo = repo
|
2013-12-19 23:01:34 +00:00
|
|
|
t.name = name
|
|
|
|
t.offset = offset
|
|
|
|
t.size = size
|
|
|
|
return t.data, nil
|
|
|
|
}
|
|
|
|
|
2013-12-31 02:21:57 +00:00
|
|
|
func (t *TestModel) Close(nodeID string, err error) {
|
2013-12-19 23:01:34 +00: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
|
|
|
|
}
|
2014-02-24 12:29:30 +00:00
|
|
|
return e.PipeWriter.Write(data)
|
2013-12-19 23:01:34 +00:00
|
|
|
}
|