本文整理汇总了Golang中github.com/anacrolix/torrent/metainfo.Info类的典型用法代码示例。如果您正苦于以下问题:Golang Info类的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Info类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: OpenTorrentData
func (me *store) OpenTorrentData(info *metainfo.Info) (ret *data) {
ret = &data{info, me}
for i := range iter.N(info.NumPieces()) {
go ret.PieceComplete(i)
}
return
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:7,代码来源:store.go
示例2: extentCompleteRequiredLengths
func extentCompleteRequiredLengths(info *metainfo.Info, off, n int64) (ret []metainfo.FileInfo) {
if n == 0 {
return
}
for _, fi := range info.UpvertedFiles() {
if off >= fi.Length {
off -= fi.Length
continue
}
n1 := n
if off+n1 > fi.Length {
n1 = fi.Length - off
}
ret = append(ret, metainfo.FileInfo{
Path: fi.Path,
Length: off + n1,
})
n -= n1
if n == 0 {
return
}
off = 0
}
panic("extent exceeds torrent bounds")
}
开发者ID:ymonk,项目名称:torrent,代码行数:25,代码来源:file_misc.go
示例3: TorrentData
func TorrentData(md *metainfo.Info, location string) (ret *torrentData, err error) {
var mms mmap_span.MMapSpan
defer func() {
if err != nil {
mms.Close()
}
}()
for _, miFile := range md.UpvertedFiles() {
fileName := filepath.Join(append([]string{location, md.Name}, miFile.Path...)...)
err = os.MkdirAll(filepath.Dir(fileName), 0777)
if err != nil {
err = fmt.Errorf("error creating data directory %q: %s", filepath.Dir(fileName), err)
return
}
var file *os.File
file, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return
}
func() {
defer file.Close()
var fi os.FileInfo
fi, err = file.Stat()
if err != nil {
return
}
if fi.Size() < miFile.Length {
err = file.Truncate(miFile.Length)
if err != nil {
return
}
}
if miFile.Length == 0 {
// Can't mmap() regions with length 0.
return
}
var mMap mmap.MMap
mMap, err = mmap.MapRegion(file,
int(miFile.Length), // Probably not great on <64 bit systems.
mmap.RDWR, 0, 0)
if err != nil {
err = fmt.Errorf("error mapping file %q, length %d: %s", file.Name(), miFile.Length, err)
return
}
if int64(len(mMap)) != miFile.Length {
panic("mmap has wrong length")
}
mms.Append(mMap)
}()
if err != nil {
return
}
}
ret = &torrentData{
MMapSpan: mms,
completed: make([]bool, md.NumPieces()),
}
return
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:59,代码来源:mmap.go
示例4: validateInfo
func validateInfo(info *metainfo.Info) error {
if len(info.Pieces)%20 != 0 {
return errors.New("pieces has invalid length")
}
if int((info.TotalLength()+info.PieceLength-1)/info.PieceLength) != info.NumPieces() {
return errors.New("piece count and file lengths are at odds")
}
return nil
}
开发者ID:gbjk,项目名称:torrent,代码行数:9,代码来源:misc.go
示例5: TorrentData
func TorrentData(md *metainfo.Info, location string) (mms *mmap_span.MMapSpan, err error) {
mms = &mmap_span.MMapSpan{}
defer func() {
if err != nil {
mms.Close()
mms = nil
}
}()
for _, miFile := range md.UpvertedFiles() {
fileName := filepath.Join(append([]string{location, md.Name}, miFile.Path...)...)
err = os.MkdirAll(filepath.Dir(fileName), 0777)
if err != nil {
err = fmt.Errorf("error creating data directory %q: %s", filepath.Dir(fileName), err)
return
}
var file *os.File
file, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return
}
func() {
defer file.Close()
var fi os.FileInfo
fi, err = file.Stat()
if err != nil {
return
}
if fi.Size() < miFile.Length {
err = file.Truncate(miFile.Length)
if err != nil {
return
}
}
if miFile.Length == 0 {
// Can't mmap() regions with length 0.
return
}
var mMap gommap.MMap
mMap, err = gommap.MapRegion(file.Fd(), 0, miFile.Length, gommap.PROT_READ|gommap.PROT_WRITE, gommap.MAP_SHARED)
if err != nil {
err = fmt.Errorf("error mapping file %q, length %d: %s", file.Name(), miFile.Length, err)
return
}
if int64(len(mMap)) != miFile.Length {
panic("mmap has wrong length")
}
mms.Append(mMap)
}()
if err != nil {
return
}
}
return
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:54,代码来源:mmap.go
示例6: TorrentData
func TorrentData(md *metainfo.Info, location string) data {
return data{md, location, make([]bool, md.NumPieces())}
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:3,代码来源:file.go
注:本文中的github.com/anacrolix/torrent/metainfo.Info类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论