]> Sergey Matveev's repositories - btrtrc.git/blob - example_test.go
Merge pull request #9 from gitter-badger/gitter-badge
[btrtrc.git] / example_test.go
1 package torrent_test
2
3 import (
4         "io"
5         "log"
6
7         "github.com/anacrolix/torrent"
8 )
9
10 func Example() {
11         c, _ := torrent.NewClient(nil)
12         defer c.Close()
13         t, _ := c.AddMagnet("magnet:?xt=urn:btih:ZOCMZQIPFFW7OLLMIC5HUB6BPCSDEOQU")
14         <-t.GotInfo()
15         t.DownloadAll()
16         c.WaitAll()
17         log.Print("ermahgerd, torrent downloaded")
18 }
19
20 func Example_fileReader() {
21         var (
22                 t torrent.Torrent
23                 f torrent.File
24         )
25         r := t.NewReader()
26         defer r.Close()
27         // Access the parts of the torrent pertaining to f. Data will be
28         // downloaded as required, per the configuration of the torrent.Reader.
29         _ = io.NewSectionReader(r, f.Offset(), f.Length())
30 }