Example #1
0
func (cl *Client) AddTorrent(mi *metainfo.MetaInfo) (T *Torrent, err error) {
	T, _, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
	var ss []string
	missinggo.CastSlice(&ss, mi.Nodes)
	cl.AddDHTNodes(ss)
	return
}
Example #2
0
func (me Bitmap) ToSortedSlice() (ret []int) {
	if me.rb == nil {
		return
	}
	missinggo.CastSlice(&ret, me.rb.ToArray())
	return
}
Example #3
0
func TestGroupByNiladicKey(t *testing.T) {
	const s = "AAAABBBCCD"
	gb := GroupBy(StringIterator(s), func(interface{}) interface{} { return nil })
	gb.Next()
	var ss []byte
	g := IteratorAsSlice(gb.Value().(Iterator))
	missinggo.CastSlice(&ss, g)
	assert.Equal(t, s, string(ss))
}
Example #4
0
func (b *Batch) write_torrent(w io.Writer) error {
	var td MetaInfo

	// Either announce or node lists are allowed - not both
	if len(b.announce_list) != 0 {
		td.Announce = b.announce_list[0][0]
		if len(b.announce_list) != 1 || len(b.announce_list[0]) != 1 {
			td.AnnounceList = b.announce_list
		}
	}

	missinggo.CastSlice(&td.Nodes, b.node_list)
	td.CreationDate = b.creation_date.Unix()
	td.Comment = b.comment
	td.CreatedBy = b.created_by
	td.Encoding = b.encoding
	switch {
	case len(b.urls) == 0:
	case len(b.urls) == 1:
		td.URLList = b.urls[0]
	default:
		td.URLList = b.urls
	}

	td.Info.PieceLength = b.piece_length
	td.Info.Pieces = b.pieces
	if b.name == "" {
		td.Info.Name = b.default_name
	} else {
		td.Info.Name = b.name
	}
	if len(b.files) == 1 {
		td.Info.Length = b.files[0].size
	} else {
		td.Info.Files = make([]FileInfo, len(b.files))
		for i, f := range b.files {
			td.Info.Files[i] = FileInfo{
				Path:   f.splitpath,
				Length: f.size,
			}
		}
	}
	td.Info.Private = b.private

	e := bencode.NewEncoder(w)
	return e.Encode(&td)
}
Example #5
0
// TODO: Include URIs that weren't converted to tracker clients.
func (t *Torrent) announceList() (al [][]string) {
	missinggo.CastSlice(&al, t.trackers)
	return
}
Example #6
0
func bitmapSlice(bm *Bitmap) (ret []int) {
	sl := itertools.IterableAsSlice(bm)
	missinggo.CastSlice(&ret, sl)
	return
}