2
0
mirror of synced 2025-02-23 14:18:13 +00:00
torrent/example_test.go
2015-06-03 13:30:55 +10:00

30 lines
547 B
Go

package torrent_test
import (
"io"
"log"
"github.com/anacrolix/torrent"
)
func Example() {
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")
}
func Example_fileReader() {
var (
t torrent.Torrent
f torrent.File
)
r := t.NewReader()
defer r.Close()
fr := io.NewSectionReader(r, f.Offset(), f.Length())
// fr will read from the parts of the torrent pertaining to f.
}