Add storage/disabled
The default storage will create empty files on torrent open, which is undesirable in some circumstances. This storage implementation is explicit about not storing anything.
This commit is contained in:
parent
bc186ac211
commit
ef39f408fe
58
storage/disabled/disabled.go
Normal file
58
storage/disabled/disabled.go
Normal file
@ -0,0 +1,58 @@
|
||||
package disabled
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/anacrolix/torrent/storage"
|
||||
)
|
||||
|
||||
type Client struct{}
|
||||
|
||||
var capacity int64
|
||||
|
||||
func (c Client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage.TorrentImpl, error) {
|
||||
capFunc := func() *int64 {
|
||||
return &capacity
|
||||
}
|
||||
return storage.TorrentImpl{
|
||||
Piece: func(piece metainfo.Piece) storage.PieceImpl {
|
||||
return Piece{}
|
||||
},
|
||||
Close: func() error {
|
||||
return nil
|
||||
},
|
||||
Capacity: &capFunc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c Client) capacity() *int64 {
|
||||
return &capacity
|
||||
}
|
||||
|
||||
type Piece struct{}
|
||||
|
||||
func (Piece) ReadAt(p []byte, off int64) (n int, err error) {
|
||||
err = errors.New("disabled")
|
||||
return
|
||||
}
|
||||
|
||||
func (Piece) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
err = errors.New("disabled")
|
||||
return
|
||||
}
|
||||
|
||||
func (Piece) MarkComplete() error {
|
||||
return errors.New("disabled")
|
||||
}
|
||||
|
||||
func (Piece) MarkNotComplete() error {
|
||||
return errors.New("disabled")
|
||||
}
|
||||
|
||||
func (Piece) Completion() storage.Completion {
|
||||
return storage.Completion{
|
||||
Complete: false,
|
||||
Ok: true,
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user