aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-08 23:33:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-08 23:33:34 +0200
commit79cb847f46928401b152bc052addad3458565e7a (patch)
tree45778fc2bd65ab5c5857771b3499b7bf2030349e
parent23b6477ebbf3f6ab3b622510c06b59af7183d357 (diff)
Comments
-rw-r--r--meta/info.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/meta/info.go b/meta/info.go
index 57aa937..bdcb894 100644
--- a/meta/info.go
+++ b/meta/info.go
@@ -59,7 +59,7 @@ func (i Info) GetPieces() []Piece {
return p
}
-// Open N-th file and allocate required path
+// Open N-th file and allocate required path on demand
func (i Info) Open(n int) (*os.File, error) {
var p string
if len(i.Files) == 0 {
@@ -78,6 +78,9 @@ func (i Info) Offset(piece int) int {
return i.PieceLength * piece
}
+// FindFile looks up first file # corresponding to offset in gross buffer
+// If piece is bigger the next file(s) with offset 0 shall be used to
+// fit a piece into
func (i Info) FindFile(off int) (int, int) {
for n, l := range i.Files {
if l.Length > off {
@@ -93,6 +96,11 @@ func (i Info) FindFile(off int) (int, int) {
* |----|----|----|----|----|----|----|--| pieces
* |-|----|--|----|----------|-|----|----| files
* 0 1 2 3 4 5 6 7 #file
+ *
+ * 0 2 3 4 #piece
+ * |--------|--------|--------|-----| pieces
+ * |-|--|--|-|--|--|-------------|--| files
+ * 0 1 2 3 4 5 6 7 #file
*/
// FIXME WriteAt ...