aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-26 21:29:27 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-26 21:29:27 +0200
commitddc7e330e6180db8d17488f67a109a2e3be97eae (patch)
treefbcde5ba4c8ee2ed77881a65fe5005b304d98b8f
parent58dc7932c4e26e312bf10e27c247527e577ca945 (diff)
random bits
-rw-r--r--meta/torrent.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index d6ebfe5..b5a4bb2 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -33,8 +33,7 @@ func (i Info) FullPath(n int) (string, error) {
if n >= len(i.Files) || n < 0 {
return "", errors.New("out of range")
}
- p := append([]string{i.Name}, i.Files[n].Path...)
- return path.Join(p...), nil
+ return path.Join(append([]string{i.Name}, i.Files[n].Path...)...), nil
}
// piece-to-file mapping:
@@ -53,11 +52,19 @@ func (i Info) FindFile(chunk, offset int) int {
return 0
}
-func (i Info) WriteAt(p []byte, off int64) (n int, err error) {
+func (i Info) WriteAt(b []byte, off int64) (n int, err error) {
return 0, ErrNotImplemented
}
-func (i Info) ReadAt(p []byte, off int64) (n int, err error) {
+func (i Info) ReadAt(b []byte, off int64) (n int, err error) {
+ if i.isSingleFile() {
+ fd, err := os.OpenFile(i.Name, os.O_RDWR|os.O_CREATE, 0644)
+ if err != nil {
+ return 0, err
+ }
+ defer fd.Close()
+ return fd.ReadAt(b, int64(i.PieceLength)*off)
+ }
return 0, ErrNotImplemented
}