当前位置: 首页>>代码示例>>Golang>>正文


Golang Builder.AddAnnounceGroup方法代码示例

本文整理汇总了Golang中github.com/anacrolix/torrent/metainfo.Builder.AddAnnounceGroup方法的典型用法代码示例。如果您正苦于以下问题:Golang Builder.AddAnnounceGroup方法的具体用法?Golang Builder.AddAnnounceGroup怎么用?Golang Builder.AddAnnounceGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/anacrolix/torrent/metainfo.Builder的用法示例。


在下文中一共展示了Builder.AddAnnounceGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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.AddAnnounceGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。