mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 06:43:42 +00:00
Refactor
This commit is contained in:
1 parent
075852b847
commit
adb7d89018
19 files changed
+415
-258
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user