kraken

Форк
0
/
storage.go 
65 строк · 1.8 Кб
1
// Copyright (c) 2016-2019 Uber Technologies, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
package storage
15

16
import (
17
	"errors"
18
	"io"
19

20
	"github.com/uber/kraken/core"
21

22
	"github.com/willf/bitset"
23
)
24

25
// ErrNotFound occurs when TorrentArchive cannot found a torrent.
26
var ErrNotFound = errors.New("torrent not found")
27

28
// ErrPieceComplete occurs when Torrent cannot write a piece because it is already
29
// complete.
30
var ErrPieceComplete = errors.New("piece is already complete")
31

32
// PieceReader defines operations for lazy piece reading.
33
type PieceReader interface {
34
	io.ReadCloser
35
	Length() int
36
}
37

38
// Torrent represents a read/write interface for a torrent
39
type Torrent interface {
40
	Digest() core.Digest
41
	Stat() *TorrentInfo
42
	NumPieces() int
43
	Length() int64
44
	PieceLength(piece int) int64
45
	MaxPieceLength() int64
46
	InfoHash() core.InfoHash
47
	Complete() bool
48
	BytesDownloaded() int64
49
	Bitfield() *bitset.BitSet
50
	String() string
51

52
	HasPiece(piece int) bool
53
	MissingPieces() []int
54

55
	WritePiece(src PieceReader, piece int) error
56
	GetPieceReader(piece int) (PieceReader, error)
57
}
58

59
// TorrentArchive creates and open torrent file
60
type TorrentArchive interface {
61
	Stat(namespace string, d core.Digest) (*TorrentInfo, error)
62
	CreateTorrent(namespace string, d core.Digest) (Torrent, error)
63
	GetTorrent(namespace string, d core.Digest) (Torrent, error)
64
	DeleteTorrent(d core.Digest) error
65
}
66

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.