本文整理汇总了Golang中github.com/anacrolix/torrent/metainfo.Builder类的典型用法代码示例。如果您正苦于以下问题:Golang Builder类的具体用法?Golang Builder怎么用?Golang Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Builder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateMetaInfo
// Writes to w, a metainfo containing the file at name.
func CreateMetaInfo(name string, w io.Writer) {
builder := metainfo.Builder{}
builder.AddFile(name)
builder.AddAnnounceGroup([]string{"lol://cheezburger"})
builder.SetPieceLength(5)
batch, err := builder.Submit()
if err != nil {
panic(err)
}
errs, _ := batch.Start(w, 1)
<-errs
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:13,代码来源:testutil.go
示例2: createTorrent
func (v Video) createTorrent() error {
log.Println("creating torrent")
f, err := os.Create(v.torrentFilename())
defer f.Close()
if err != nil {
return err
}
b := torrent.Builder{}
b.AddFile(v.OutputFilename)
for _, group := range builtinAnnounceList {
b.AddAnnounceGroup(group)
}
batch, err := b.Submit()
if err != nil {
log.Fatal(err)
}
errs, status := batch.Start(f, runtime.NumCPU())
lastProgress := int64(-1)
for {
select {
case err, ok := <-errs:
if !ok || err == nil {
return err
}
log.Print(err)
case bytesDone := <-status:
progress := 100 * bytesDone / batch.TotalSize()
if progress != lastProgress {
log.Printf("%d%%", progress)
lastProgress = progress
}
}
}
}
开发者ID:ernado,项目名称:twitch,代码行数:34,代码来源:prepare.go
示例3: TestInfohash
func TestInfohash(t *testing.T) {
os.RemoveAll(filepath.Join(os.TempDir(), "torrent-test"))
os.MkdirAll(filepath.Join(os.TempDir(), "torrent-test"), 0700)
var cl_one *Client
var cf_one *Config
var err error
if err != nil {
t.Fatal(err)
}
cf_one = testingConfig()
cf_one.ListenAddr = "localhost:43433"
cf_one = addirs(cf_one)
cl_one, err = NewClient(cf_one)
if err != nil {
t.Fatal(err)
}
tfp := filepath.Join(cf_one.DataDir, "testdata")
writeranddata(tfp)
b := metainfo.Builder{}
b.AddFile(tfp)
b.AddDhtNodes([]string{fmt.Sprintf(cl_one.DHT().ID())})
ba, err := b.Submit()
if err != nil {
t.Fatal(err)
}
ttfp := filepath.Join(cf_one.ConfigDir, "/../torrent")
ttf, err := os.Create(ttfp)
if err != nil {
t.Fatal(err)
}
ec, _ := ba.Start(ttf, runtime.NumCPU())
err = <-ec
if err != nil {
t.Fatal(err)
}
ttf.Close()
tor, err := cl_one.AddTorrentFromFile(ttfp)
if err != nil {
t.Fatal(err)
}
<-tor.GotInfo()
tor.DownloadAll()
if cl_one.WaitAll() == false {
t.Fatal(errors.New("One did not download torrent"))
}
}
开发者ID:CooCooooo,项目名称:torrent,代码行数:47,代码来源:issue35_test.go
示例4: main
func main() {
b := torrent.Builder{}
for _, filename := range flag.Args() {
if err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return err
}
log.Print(path)
if info.IsDir() {
return nil
}
b.AddFile(path)
return nil
}); err != nil {
log.Print(err)
}
}
for _, group := range builtinAnnounceList {
b.AddAnnounceGroup(group)
}
batch, err := b.Submit()
if err != nil {
log.Fatal(err)
}
errs, status := batch.Start(os.Stdout, runtime.NumCPU())
lastProgress := int64(-1)
for {
select {
case err, ok := <-errs:
if !ok || err == nil {
return
}
log.Print(err)
case bytesDone := <-status:
progress := 100 * bytesDone / batch.TotalSize()
if progress != lastProgress {
log.Printf("%d%%", progress)
lastProgress = progress
}
}
}
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:42,代码来源:main.go
示例5: CreateTorrent
func (b *Builtin) CreateTorrent(path, torrentPath string, trackers []string) (err error) {
builder := metainfo.Builder{}
builder.AddFile(path)
builder.AddAnnounceGroup(trackers)
batch, err := builder.Submit()
if err != nil {
return
}
torrentFile, err := os.Create(torrentPath)
if err != nil {
return
}
defer torrentFile.Close()
errs, _ := batch.Start(torrentFile, runtime.NumCPU())
err = <-errs
if err != nil {
return
}
return
}
开发者ID:ywk253100,项目名称:registry_p2p,代码行数:24,代码来源:builtin.go
注:本文中的github.com/anacrolix/torrent/metainfo.Builder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论