]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add File.Progress
authorMatt Joiner <anacrolix@gmail.com>
Mon, 9 Feb 2015 13:18:59 +0000 (00:18 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 9 Feb 2015 13:18:59 +0000 (00:18 +1100)
client.go

index d043f06704574ede1919131543dbb30f099d2e37..9fe47f0655b4651e7ccaf04765182576c89fce4a 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1653,12 +1653,37 @@ type File struct {
        path   string
        offset int64
        length int64
+       metainfo.FileInfo
 }
 
 func (f *File) Length() int64 {
        return f.length
 }
 
+type FilePieceState struct {
+       Length int64
+       State  byte
+}
+
+func (f *File) Progress() (ret []FilePieceState) {
+       pieceSize := int64(f.t.UsualPieceSize())
+       off := f.offset % pieceSize
+       remaining := f.length
+       for i := int(f.offset / pieceSize); ; i++ {
+               if remaining == 0 {
+                       break
+               }
+               len1 := pieceSize - off
+               if len1 > remaining {
+                       len1 = remaining
+               }
+               ret = append(ret, FilePieceState{len1, f.t.pieceStatusChar(i)})
+               off = 0
+               remaining -= len1
+       }
+       return
+}
+
 func (f *File) PrioritizeRegion(off, len int64) {
        if off < 0 || off >= f.length {
                return
@@ -1680,6 +1705,7 @@ func (t Torrent) Files() (ret []File) {
                        strings.Join(fi.Path, "/"),
                        offset,
                        fi.Length,
+                       fi,
                })
                offset += fi.Length
        }