FedP2P/example_test.go

31 lines
620 B
Go
Raw Normal View History

package torrent_test
import (
2015-06-03 11:30:55 +08:00
"io"
"log"
"github.com/anacrolix/torrent"
)
func Example() {
2015-06-03 11:30:55 +08:00
c, _ := torrent.NewClient(nil)
defer c.Close()
t, _ := c.AddMagnet("magnet:?xt=urn:btih:ZOCMZQIPFFW7OLLMIC5HUB6BPCSDEOQU")
<-t.GotInfo()
t.DownloadAll()
c.WaitAll()
log.Print("ermahgerd, torrent downloaded")
}
2015-06-03 11:30:55 +08:00
func Example_fileReader() {
var (
t torrent.Torrent
f torrent.File
)
r := t.NewReader()
defer r.Close()
2015-06-04 12:25:52 +08:00
// Access the parts of the torrent pertaining to f. Data will be
// downloaded as required, per the configuration of the torrent.Reader.
2015-06-03 11:48:57 +08:00
_ = io.NewSectionReader(r, f.Offset(), f.Length())
2015-06-03 11:30:55 +08:00
}