]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add storage/disabled
authorMatt Joiner <anacrolix@gmail.com>
Mon, 24 May 2021 07:38:09 +0000 (17:38 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 7 Jun 2021 03:01:40 +0000 (13:01 +1000)
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.

storage/disabled/disabled.go [new file with mode: 0644]

diff --git a/storage/disabled/disabled.go b/storage/disabled/disabled.go
new file mode 100644 (file)
index 0000000..22d5143
--- /dev/null
@@ -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,
+       }
+}