• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang metainfo.Piece类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: pieceComplete

func (me *store) pieceComplete(p metainfo.Piece) bool {
	if me.completionKnown(p) {
		return me.isComplete(p)
	}
	// Prevent a errors from stalling the caller.
	if !me.lastError.IsZero() && time.Since(me.lastError) < time.Second {
		return false
	}
	length, err := me.db.GetLength(me.completedPiecePath(p))
	if err == dataBackend.ErrNotFound {
		me.setCompletion(p, false)
		return false
	}
	if err != nil {
		me.lastError = time.Now()
		log.Printf("%+v", err)
		return false
	}
	complete := length == p.Length()
	if !complete {
		log.Printf("completed piece %x has wrong length: %d", p.Hash(), length)
	}
	me.setCompletion(p, complete)
	return complete
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:25,代码来源:store.go


示例2: path

func (me *store) path(p metainfo.Piece, completed bool) string {
	return filepath.Join(me.baseDir, func() string {
		if completed {
			return "complete"
		} else {
			return "incomplete"
		}
	}(), fmt.Sprintf("%x", p.Hash()))
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:9,代码来源:store.go


示例3: Set

func (me *mapPieceCompletion) Set(p metainfo.Piece, b bool) error {
	if b {
		if me.m == nil {
			me.m = make(map[metainfo.PieceKey]struct{})
		}
		me.m[p.Key()] = struct{}{}
	} else {
		delete(me.m, p.Key())
	}
	return nil
}
开发者ID:ymonk,项目名称:torrent,代码行数:11,代码来源:completion_piece_map.go


示例4: PieceCompleted

func (me *store) PieceCompleted(p metainfo.Piece) (err error) {
	hash, err := me.hashCopyFile(me.incompletePiecePath(p), me.completedPiecePath(p), p.Length())
	if err == nil && !bytes.Equal(hash, p.Hash()) {
		err = errors.New("piece incomplete")
	}
	if err != nil {
		me.deleteCompleted(p)
		return
	}
	me.removePath(me.incompletePiecePath(p))
	me.setCompletion(p, true)
	return
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:13,代码来源:store.go


示例5: PieceCompleted

func (me *store) PieceCompleted(p metainfo.Piece) (err error) {
	err = me.makeSpace(p.Length())
	if err != nil {
		return
	}
	var (
		incompletePiecePath = me.path(p, false)
		completedPiecePath  = me.path(p, true)
	)
	fSrc, err := os.Open(incompletePiecePath)
	if err != nil {
		return
	}
	defer fSrc.Close()
	os.MkdirAll(filepath.Dir(completedPiecePath), dirPerm)
	fDst, err := os.OpenFile(completedPiecePath, os.O_EXCL|os.O_CREATE|os.O_WRONLY, filePerm)
	if err != nil {
		return
	}
	defer fDst.Close()
	hasher := sha1.New()
	r := io.TeeReader(io.LimitReader(fSrc, p.Length()), hasher)
	_, err = io.Copy(fDst, r)
	if err != nil {
		return
	}
	if !bytes.Equal(hasher.Sum(nil), p.Hash()) {
		err = errors.New("piece incomplete")
		os.Remove(completedPiecePath)
		return
	}
	os.Remove(incompletePiecePath)
	me.completed[sliceToPieceHashArray(p.Hash())] = struct{}{}
	return
}
开发者ID:gbjk,项目名称:torrent,代码行数:35,代码来源:store.go


示例6: Piece

func (s *piecePerResource) Piece(p metainfo.Piece) Piece {
	completed, err := s.p.NewInstance(path.Join("completed", p.Hash().HexString()))
	if err != nil {
		panic(err)
	}
	incomplete, err := s.p.NewInstance(path.Join("incomplete", p.Hash().HexString()))
	if err != nil {
		panic(err)
	}
	return piecePerResourcePiece{
		p: p,
		c: completed,
		i: incomplete,
	}
}
开发者ID:jakop345,项目名称:torrent,代码行数:15,代码来源:piece_resource.go


示例7: Piece

func (me *mmapTorrentStorage) Piece(p metainfo.Piece) Piece {
	return mmapStoragePiece{
		storage:  me,
		p:        p,
		ReaderAt: io.NewSectionReader(me.span, p.Offset(), p.Length()),
		WriterAt: missinggo.NewSectionWriter(me.span, p.Offset(), p.Length()),
	}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:8,代码来源:mmap.go


示例8: Piece

func (fts *fileTorrentStorage) Piece(p metainfo.Piece) Piece {
	// Create a view onto the file-based torrent storage.
	_io := fileStorageTorrent{fts}
	// Return the appropriate segments of this.
	return &fileStoragePiece{
		fts,
		p,
		missinggo.NewSectionWriter(_io, p.Offset(), p.Length()),
		io.NewSectionReader(_io, p.Offset(), p.Length()),
	}
}
开发者ID:ymonk,项目名称:torrent,代码行数:11,代码来源:file.go


示例9: Piece

func (me *fileStorage) Piece(p metainfo.Piece) Piece {
	_io := &fileStorageTorrent{
		p.Info,
		me.baseDir,
	}
	return &fileStoragePiece{
		me,
		p,
		missinggo.NewSectionWriter(_io, p.Offset(), p.Length()),
		io.NewSectionReader(_io, p.Offset(), p.Length()),
	}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:file.go


示例10: pieceRead

// Returns the file for the given piece, if it exists. It could be completed,
// or incomplete.
func (me *store) pieceRead(p metainfo.Piece) (f *os.File) {
	f, err := os.Open(me.path(p, true))
	if err == nil {
		return
	}
	if !os.IsNotExist(err) {
		panic(err)
	}
	// Mark the file not completed, in case we thought it was. TODO: Trigger
	// an asynchronous initCompleted to reinitialize the entire completed map
	// as there are likely other files missing.
	me.mu.Lock()
	delete(me.completed, sliceToPieceHashArray(p.Hash()))
	me.mu.Unlock()
	f, err = os.Open(me.path(p, false))
	if err == nil {
		return
	}
	if !os.IsNotExist(err) {
		panic(err)
	}
	return
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:25,代码来源:store.go


示例11: Get

func (me *dbPieceCompletion) Get(p metainfo.Piece) (ret bool, err error) {
	row := me.db.QueryRow(`select exists(select * from completed where infohash=? and "index"=?)`, p.Info.Hash().HexString(), p.Index())
	err = row.Scan(&ret)
	return
}
开发者ID:ymonk,项目名称:torrent,代码行数:5,代码来源:db.go


示例12: pieceReader

func (me *data) pieceReader(p metainfo.Piece, off int64) (ret io.ReadCloser, err error) {
	return me.store.getPieceRange(p, off, p.Length()-off)
}
开发者ID:ngaut,项目名称:torrent,代码行数:3,代码来源:blob.go


示例13: pieceHashArray

func pieceHashArray(p metainfo.Piece) [20]byte {
	return sliceToPieceHashArray(p.Hash())
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:3,代码来源:store.go


示例14: incompletePiecePath

func (me *store) incompletePiecePath(p metainfo.Piece) string {
	return path.Join(
		"incomplete",
		strconv.FormatInt(int64(os.Getpid()), 10),
		hex.EncodeToString(p.Hash()))
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:6,代码来源:store.go


示例15: completedPiecePath

func (me *store) completedPiecePath(p metainfo.Piece) string {
	return path.Join("completed", hex.EncodeToString(p.Hash()))
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:3,代码来源:store.go


示例16: pieceComplete

func (me *store) pieceComplete(p metainfo.Piece) bool {
	_, ok := me.completed[sliceToPieceHashArray(p.Hash())]
	return ok
}
开发者ID:gbjk,项目名称:torrent,代码行数:4,代码来源:store.go


示例17: pieceComplete

func (me *store) pieceComplete(p metainfo.Piece) bool {
	me.mu.Lock()
	defer me.mu.Unlock()
	_, ok := me.completed[sliceToPieceHashArray(p.Hash())]
	return ok
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:6,代码来源:store.go


示例18: Set

func (me *dbPieceCompletion) Set(p metainfo.Piece, b bool) (err error) {
	if b {
		_, err = me.db.Exec(`insert into completed (infohash, "index") values (?, ?)`, p.Info.Hash().HexString(), p.Index())
	} else {
		_, err = me.db.Exec(`delete from completed where infohash=? and "index"=?`, p.Info.Hash().HexString(), p.Index())
	}
	return
}
开发者ID:ymonk,项目名称:torrent,代码行数:8,代码来源:db.go


示例19: Get

func (me *mapPieceCompletion) Get(p metainfo.Piece) (bool, error) {
	_, ok := me.m[p.Key()]
	return ok, nil
}
开发者ID:ymonk,项目名称:torrent,代码行数:4,代码来源:completion_piece_map.go



注:本文中的github.com/anacrolix/torrent/metainfo.Piece类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang peer_protocol.Integer函数代码示例发布时间:2022-05-24
下一篇:
Golang metainfo.InfoEx类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap