This commit is contained in:
liwei committed 2019-09-12 18:57:17 +08:00
1 parent 075852b847
commit adb7d89018
19 files changed
+415 -258

No files matched your search

+15 -3
View File
@@ -39,8 +39,8 @@ type File struct {
}
type ExtraInfo struct {
InfoHash [20]byte
FileSize uint64
InfoHash [20]byte
TotalSize uint64
}
func ParseFromFile(path string) (*MetaInfo, error) {
@@ -75,10 +75,22 @@ func ParseFromFile(path string) (*MetaInfo, error) {
}
}
}
metaInfo.FileSize = getTotalSize(&metaInfo)
metaInfo.TotalSize = getTotalSize(&metaInfo)
return &metaInfo, nil
}
// 获取某个分片的大小
func (metaInfo *MetaInfo) GetPieceSize(index int) uint64 {
// 是否为最后一个分片
if index == len(metaInfo.Info.Pieces)-1 {
size := metaInfo.TotalSize % metaInfo.Info.PieceLength
if size > 0 {
return size
}
}
return metaInfo.Info.PieceLength
}
func getTotalSize(metaInfo *MetaInfo) uint64 {
if metaInfo.Info != nil {
if len(metaInfo.Info.Files) > 0 {