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


Golang Piece.Length方法代码示例

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


在下文中一共展示了Piece.Length方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

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

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

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


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