Categorygithub.com/moreal/bencodex-go
repositorypackage
0.0.0-20231021172012-18277a477d15
Repository: https://github.com/moreal/bencodex-go.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

go-bencode

Software License Build Status Coverage Status Go Report Card Go Doc

Installation

go get github.com/moreal/bencodex-go

import bencode "github.com/moreal/bencodex-go"

Quick Start

var dict interface{} = map[string]interface{}{
	"int":    123,
	"string": "Hello, World",
	"list":   []interface{}{"foo", "bar"},
}
data, err := bencodex.Marshal(dict)
if err != nil {
	panic(err)
}
fmt.Println(string(data))

// Output:
// d3:inti123e4:listl3:foo3:bare6:string12:Hello, Worlde
data, err := bencodex.Unmarshal(value)

Performance benchmarks

Go 1.16, Debian 9.1, i7-7700

Marshal

LibraryTimeBytes AllocatedObjects AllocatedNotes
IncSW/go-bencode598.5 ns/op512 B/op1 allocs/op
cristalhq/bencode939.4 ns/op928 B/op4 allocs/op
marksamman/bencode1002 ns/op736 B/op9 allocs/op4
aleksatr/go-bencode1060 ns/op736 B/op9 allocs/op
chihaya/chihaya1722 ns/op1009 B/op53 allocs/op1
lajide/bencode1725 ns/op1011 B/op53 allocs/op1
nabilanam/bencode2865 ns/op3192 B/op54 allocs/op5
anacrolix/torrent3179 ns/op1328 B/op25 allocs/op
lwch/bencode3340 ns/op1792 B/op75 allocs/op1, 2
tumdum/bencoding3419 ns/op1752 B/op60 allocs/op
stints/bencode4018 ns/op3120 B/op100 allocs/op1, 2
ehmry/go-bencode4569 ns/op1496 B/op33 allocs/op
jackpal/bencode-go4702 ns/op2016 B/op45 allocs/op
zeebo/bencode5003 ns/op1376 B/op33 allocs/op
owenliang/dht5180 ns/op3279 B/op80 allocs/op5
cuberat/go-bencode5589 ns/op1929 B/op71 allocs/op2

MarshalTo

LibraryTimeBytes AllocatedObjects AllocatedNotes
IncSW/go-bencode503.0 ns/op0 B/op0 allocs/op
cristalhq/bencode668.4 ns/op0 B/op0 allocs/op
chihaya/chihaya1432 ns/op307 B/op49 allocs/op1
lajide/bencode1462 ns/op307 B/op49 allocs/op1
anacrolix/torrent2954 ns/op720 B/op21 allocs/op
lwch/bencode3093 ns/op1089 B/op71 allocs/op1, 2
tumdum/bencoding3474 ns/op1752 B/op60 allocs/op
jackpal/bencode-go4479 ns/op1408 B/op41 allocs/op
ehmry/go-bencode4650 ns/op1528 B/op33 allocs/op
cuberat/go-bencode5360 ns/op1321 B/op67 allocs/op2

Unmarshal

LibraryTimeBytes AllocatedObjects AllocatedNotes
IncSW/go-bencode991.5 ns/op960 B/op18 allocs/op
cristalhq/bencode1160 ns/op960 B/op18 allocs/op
nabilanam/bencode1379 ns/op1240 B/op39 allocs/op
owenliang/dht1702 ns/op1352 B/op46 allocs/op
aleksatr/go-bencode2279 ns/op1816 B/op51 allocs/op
jackpal/bencode-go2597 ns/op1688 B/op59 allocs/op
marksamman/bencode2758 ns/op5768 B/op54 allocs/op
ehmry/go-bencode2865 ns/op2064 B/op41 allocs/op
chihaya/chihaya2961 ns/op5880 B/op61 allocs/op
lajide/bencode2973 ns/op5880 B/op61 allocs/op
anacrolix/torrent3723 ns/op2456 B/op62 allocs/op
cuberat/go-bencode4687 ns/op6544 B/op119 allocs/op
zeebo/bencode5954 ns/op6376 B/op91 allocs/op
tumdum/bencoding7891 ns/op6568 B/op157 allocs/op
lwch/bencode---3
stints/bencode---6

RealWorld ubuntu-21.04-desktop-amd64.iso.torrent

LibraryTimeBytes AllocatedObjects Allocated
IncSW/go-bencode Unmarshal1269 ns/op1016 B/op21 allocs/op
IncSW/go-bencode Marshal27929 ns/op262816 B/op2 allocs/op
IncSW/go-bencode MarshalTo7851 ns/op0 B/op0 allocs/op
cristalhq/bencode Unmarshal1552 ns/op1016 B/op21 allocs/op
cristalhq/bencode Marshal49125 ns/op443168 B/op5 allocs/op
cristalhq/bencode MarshalTo8183 ns/op0 B/op0 allocs/op
aleksatr/go-bencode Unmarshal21615 ns/op223352 B/op69 allocs/op
aleksatr/go-bencode Marshal26401 ns/op222689 B/op13 allocs/op
jackpal/bencode-go Unmarshal48384 ns/op444484 B/op81 allocs/op
jackpal/bencode-go Marshal55097 ns/op445694 B/op60 allocs/op
jackpal/bencode-go MarshalTo35800 ns/op223128 B/op54 allocs/op

Notes

  1. BUG: Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics). http://bittorrent.org/beps/bep_0003.html#bencoding
  2. BUG: []byte encoding as a list
  3. BUG: not supported list in list
  4. WARN: ignoring unsupported types without errors
  5. INFO: just 4 types supported
  6. INFO: files only

License

MIT License.