gobencode

package module
v0.0.0-...-480291c Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 8 Imported by: 0

README

GoBencode

Library used for reading and writing bencode, usually, .torrent files

Decoder results can be printed out in JSON-like style

Examples

Take a look at the examples

Decoder output

["hello", "world", 12345, {"type": 1, "animal": "cat"}]

Encoder output

l5:hello5:worldi12345ed6:animal3:cat4:typei1eee

Go example

item := DecodeFile(filepath)
fmt.Println(item)               // ["hello", "world", 12345, {"type": 1, "animal": "cat"}]

list := item.Value.([]BencodeItem)
fmt.Println(list[0])            // "hello"

dict := list[3].Value.(map[string]BencodeItem)
fmt.Println(dict["animal"])     // "cat"

BencodeCLI

Take a look at the CLI tool based on this library. Link

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BencodeItem

type BencodeItem struct {
	Type  ItemType
	Value any
}

func DecodeFile

func DecodeFile(filepath string) BencodeItem

func DecodeString

func DecodeString(bencode string) BencodeItem

func (BencodeItem) String

func (v BencodeItem) String() string

type Decoder

type Decoder struct {
	Cursor int64
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r *bufio.Reader) Decoder

func (*Decoder) Read

func (d *Decoder) Read(p []byte)

func (*Decoder) ReadByte

func (d *Decoder) ReadByte() byte

func (*Decoder) ReadBytes

func (d *Decoder) ReadBytes(delim byte) []byte

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

type ItemType

type ItemType byte
const (
	EOL     ItemType = 0
	Integer ItemType = 1
	Bytes   ItemType = 2
	List    ItemType = 3
	Dict    ItemType = 4
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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