bencode

package
v0.6.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2021 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

bep_0012: announce-list bep_0030: Merkle hash torrent extension.

Index

Constants

View Source
const (
	Unknown    = -100
	DorLEnd    = -1 // Dictionary or List end mark.
	DictType   = 0
	ListType   = 1
	IntValue   = 2
	ByteString = 3 // Actually byte string.
	MaxDepth   = 10
)

Variables

View Source
var (
	ErrEncodeDepthTooGreat = errors.New("bencode: Bencode depth over than 10, it is abnormal!")
	ErrInvalidDictKey      = errors.New("bencode: Dictionary's key must be byte string!")
	ErrTypeFrom            = errors.New("bencode: Cannot be body after int or string.")
	ErrTooManyEnd          = errors.New("bencode: Too many end.")
)
View Source
var (
	ErrInvalidBody    = errors.New("bencode: Body did not pass Check().")
	ErrDictWithoutKey = errors.New("bencode: Dict need a key to add value.")
	ErrUnknownType    = errors.New("bencode: Unknown type to add.")
)
View Source
var (
	ErrInfoNotFound = errors.New("bencode: Did not find Info to calc infohash.")
)

Functions

This section is empty.

Types

type BEncoder

type BEncoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder() *BEncoder

func (*BEncoder) Add

func (e *BEncoder) Add(k string, val interface{}) error

func (*BEncoder) End

func (e *BEncoder) End() []*Body

func (*BEncoder) EndPart

func (e *BEncoder) EndPart() error

func (*BEncoder) NewDict

func (e *BEncoder) NewDict(k string) error

func (*BEncoder) NewList

func (e *BEncoder) NewList(k string) error

type Body

type Body struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(data []byte) (result []*Body, e error)

func NewBStr

func NewBStr(s string) *Body

func NewEmptyList

func NewEmptyList() *Body

func (*Body) AddPart

func (body *Body) AddPart(k string, v *Body) error

func (*Body) AnnounceList

func (b *Body) AnnounceList(s []string)

func (*Body) BStr

func (body *Body) BStr() []byte

func (*Body) Check

func (body *Body) Check() (f bool)

func (*Body) Delete

func (body *Body) Delete(k string)

func (*Body) DeleteN

func (body *Body) DeleteN(n int)

func (*Body) Dict

func (body *Body) Dict(key string) *Body

func (*Body) DictN

func (body *Body) DictN(n int) (k string, b *Body)

func (*Body) Edit

func (body *Body) Edit(v interface{})

func (*Body) Encode

func (body *Body) Encode() ([]byte, error)

func (*Body) Infohash

func (body *Body) Infohash() (r []byte, e error)

func (*Body) Len

func (body *Body) Len() int

func (*Body) List

func (body *Body) List(n int) *Body

func (*Body) Type

func (body *Body) Type() int

func (*Body) Value

func (body *Body) Value() int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL