metainfo/info.go | 11 ++++++----- metainfo/info_test.go | 2 ++ diff --git a/metainfo/info.go b/metainfo/info.go index 015876ed8b10776792e841f680c2d3b63e775bee..e58bb10e5821297aa12888d95421b7495a4715d2 100644 --- a/metainfo/info.go +++ b/metainfo/info.go @@ -13,11 +13,12 @@ ) // The info dictionary. See BEP 3 and BEP 52. type Info struct { - PieceLength int64 `bencode:"piece length"` // BEP3 - Pieces []byte `bencode:"pieces,omitempty"` // BEP3 - Name string `bencode:"name"` // BEP3 - NameUtf8 string `bencode:"name.utf-8,omitempty"` - Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files + PieceLength int64 `bencode:"piece length"` // BEP3 + // BEP 3. This can be omitted because isn't needed in non-hybrid v2 infos. See BEP 52. + Pieces []byte `bencode:"pieces,omitempty"` + Name string `bencode:"name"` // BEP3 + NameUtf8 string `bencode:"name.utf-8,omitempty"` + Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files ExtendedFileAttrs Private *bool `bencode:"private,omitempty"` // BEP27 // TODO: Document this field. diff --git a/metainfo/info_test.go b/metainfo/info_test.go index d65ac2f1ccade07c615a24e395ef7a2fe2f6fab2..9fd3bdedfc08ecb7dcd338f4423fe9855abbeec1 100644 --- a/metainfo/info_test.go +++ b/metainfo/info_test.go @@ -1,6 +1,7 @@ package metainfo import ( + g "github.com/anacrolix/generics" "testing" "github.com/stretchr/testify/assert" @@ -10,6 +11,7 @@ ) func TestMarshalInfo(t *testing.T) { var info Info + g.MakeSliceWithLength(&info.Pieces, 0) b, err := bencode.Marshal(info) assert.NoError(t, err) assert.EqualValues(t, "d4:name0:12:piece lengthi0e6:pieces0:e", string(b))