aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-02 05:11:12 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-02 05:11:12 +0200
commit749665df56b396d8af0b398dcb205b09660c2601 (patch)
treef348ff9d737eeb4cca43698d4281c178ad7dfc75
parent6edbf5b19304f483cf5869d9e8d9ce35ea650a5f (diff)
More examples
-rw-r--r--examples/NetBSD-7.0.1-amd64.iso.torrentbin0 -> 29937 bytes
-rw-r--r--examples/minix_R3.3.0-588a35b.iso.bz2.torrentbin0 -> 46328 bytes
-rw-r--r--meta/torrent.go11
-rw-r--r--meta/torrent_test.go20
4 files changed, 26 insertions, 5 deletions
diff --git a/examples/NetBSD-7.0.1-amd64.iso.torrent b/examples/NetBSD-7.0.1-amd64.iso.torrent
new file mode 100644
index 0000000..ca700ba
--- /dev/null
+++ b/examples/NetBSD-7.0.1-amd64.iso.torrent
Binary files differ
diff --git a/examples/minix_R3.3.0-588a35b.iso.bz2.torrent b/examples/minix_R3.3.0-588a35b.iso.bz2.torrent
new file mode 100644
index 0000000..fb9d5d8
--- /dev/null
+++ b/examples/minix_R3.3.0-588a35b.iso.bz2.torrent
Binary files differ
diff --git a/meta/torrent.go b/meta/torrent.go
index 65e74bd..886668f 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -98,15 +98,16 @@ func (i Info) Offset(piece int) int {
return i.PieceLength * piece
}
-func (i Info) FileOffset(piece int) (n, off int) {
- var l File
- off = i.PieceLength * piece
- for n, l = range i.Files {
+func (i Info) FileOffset(piece int) (int, int, bool) {
+ off := i.PieceLength * piece
+ for n, l := range i.Files {
if l.Length < off {
off -= l.Length
+ } else {
+ return n, off, off+i.PieceLength > i.Length
}
}
- return n, off
+ return 0, off, false
}
/*
diff --git a/meta/torrent_test.go b/meta/torrent_test.go
new file mode 100644
index 0000000..4965b87
--- /dev/null
+++ b/meta/torrent_test.go
@@ -0,0 +1,20 @@
+package meta
+
+import "testing"
+
+var tors = map[string]string{
+ "bsd": "OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent",
+ "ogg": "OpenBSD_songs_ogg-2016-03-25-0127.torrent",
+ "deb": "debian-8.5.0-amd64-netinst.iso.torrent",
+}
+
+func TestPieces(t *testing.T) {
+ tor, err := New("../examples/" + tors["ogg"])
+ if err != nil {
+ t.Error(err)
+ }
+ for i := 0; i < tor.Info.NPieces(); i++ {
+ n, off, span := tor.Info.FileOffset(i)
+ t.Log(n, off, span)
+ }
+}