Skip to content
프로젝트

소개

BitTorrent 피어 투 피어 파일 공유 프로토콜에서 사용하는 bencode 형식 데이터를 인코딩하고 디코딩하기 위한 Go 언어 바인딩입니다.

생산성 및 자동화

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

bencode-go

A Go language binding for encoding and decoding data in the bencode format that is used by the BitTorrent peer-to-peer file sharing protocol.

Maintenance status: ✅ Maintained (stable). This library is feature-complete — I accept bug fixes and security patches, but am not adding new features. See SECURITY.md for how to report vulnerabilities.

Quick Start

Get the package

go get -u github.com/jackpal/bencode-go

Import the package

import bencode "github.com/jackpal/bencode-go"

Unmarshal a bencode stream into an object

data := myAwesomeObject{}
err := bencode.Unmarshal(reader, &data)

Decode a bencode stream

data, err := bencode.Decode(reader)

Decode with configurable limits or strict validation

dec := bencode.NewDecoder(reader).
	SetMaxStringLength(10 * 1024 * 1024). // 10 MiB
	SetMaxDepth(50).
	SetStrict(true) // Enforces BEP 3 rules (no leading zeros, sorted keys, etc.)

data, err := dec.Decode()
// or: err := dec.Unmarshal(&myObject)

// If the stream contains trailing non-bencode data, access unread buffered bytes:
leftover := dec.Buffered()

Access raw bencoded bytes (e.g. for BitTorrent info_hash)

type Torrent struct {
	Announce string             `bencode:"announce"`
	Info     bencode.RawMessage `bencode:"info"`
}

var t Torrent
err := bencode.Unmarshal(reader, &t)
// Compute the SHA-1 info_hash directly from the raw bencoded info dictionary:
infoHash := sha1.Sum(t.Info)

Encode an object into a bencode stream

err := bencode.Marshal(writer, data)

Complete documentation

http://godoc.org/github.com/jackpal/bencode-go

License

This project is licensed under the Go Authors standard license. (See the LICENSE file for details.)

Version History

tag Notes
v1.2.2 Reject integer/float overflows in Unmarshal (thanks #26), fix nil/pointer/[]byte/bencode:"-" handling, tighten RawMessage validation, and align Decode with Unmarshal.
v1.2.1 Fix reflection panics when unmarshaling into maps with concrete element types.
v1.2.0 Added RawMessage support, Decoder.Buffered(), and skip unexported fields.
v1.1.0 Added Decoder with configurable resource limits, strict BEP 3 validation, and any types.
v1.0.2 Added go module.
v1.0.1 Removed architecture specific test that was failing on ARM.
v1.0.0 First version.

관련 프로젝트 살펴보기

불러오는 중…