Several torrents per filesystem (#38)
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
parent
ed8bd64017
commit
2a38efbb03
8 changed files with 43 additions and 46 deletions
|
@ -8,22 +8,25 @@ import (
|
|||
var _ Filesystem = &Torrent{}
|
||||
|
||||
type Torrent struct {
|
||||
t *torrent.Torrent
|
||||
s *storage
|
||||
ts []*torrent.Torrent
|
||||
s *storage
|
||||
}
|
||||
|
||||
func NewTorrent(t *torrent.Torrent) *Torrent {
|
||||
func NewTorrent(ts []*torrent.Torrent) *Torrent {
|
||||
return &Torrent{
|
||||
t: t,
|
||||
s: newStorage(SupportedFactories),
|
||||
ts: ts,
|
||||
s: newStorage(SupportedFactories),
|
||||
}
|
||||
}
|
||||
|
||||
func (fs *Torrent) load() {
|
||||
<-fs.t.GotInfo()
|
||||
for _, file := range fs.t.Files() {
|
||||
fs.s.Add(&torrentFile{readerFunc: file.NewReader, len: file.Length()}, file.Path())
|
||||
for _, t := range fs.ts {
|
||||
<-t.GotInfo()
|
||||
for _, file := range t.Files() {
|
||||
fs.s.Add(&torrentFile{readerFunc: file.NewReader, len: file.Length()}, file.Path())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (fs *Torrent) Open(filename string) (File, error) {
|
||||
|
|
|
@ -22,10 +22,10 @@ func TestTorrentFilesystem(t *testing.T) {
|
|||
client, err := torrent.NewClient(cfg)
|
||||
require.NoError(err)
|
||||
|
||||
torrent, err := client.AddMagnet(testMagnet)
|
||||
to, err := client.AddMagnet(testMagnet)
|
||||
require.NoError(err)
|
||||
|
||||
tfs := NewTorrent(torrent)
|
||||
tfs := NewTorrent([]*torrent.Torrent{to})
|
||||
|
||||
files, err := tfs.ReadDir("/")
|
||||
require.NoError(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue