Documentation
¶
Index ¶
- Constants
- func ParseBrokenTime(s string) (t time.Time, err error)
- type AnnounceAddress
- type Dictionary
- func (d *Dictionary) FillFileParameters(outNode *ft.FileTreeNode) (err error)
- func (d *Dictionary) FindDictionaryItem(name string) (item *b.DictionaryItem, err error)
- func (d *Dictionary) GetFieldValue(fieldName string) (fv any, err error)
- func (d *Dictionary) GetFieldValueAsInt(fieldName string) (fv int, err error)
- func (d *Dictionary) GetFieldValueAsString(fieldName string) (fv string, err error)
- func (d *Dictionary) GetFieldValueAsStringArray(fieldName string) (fv []string, err error)
- func (d *Dictionary) GuessFormat() (format InfoSectionFormat)
- func (d *Dictionary) GuessVersion() (version Version, err error)
- func (d *Dictionary) IsFieldPresent(fieldName string) (isFieldPresent bool)
- func (d *Dictionary) IsFileParametersNodeV2() bool
- func (d *Dictionary) ReadFilePath(isf InfoSectionFormat) (filePath []string, err error)
- func (d *Dictionary) ReadFileSize() (fs int, err error)
- func (d *Dictionary) ReadOptionalFileCrc32() (isCrc32Set bool, crc32 *hash.Crc32Sum, err error)
- func (d *Dictionary) ReadOptionalFileMd5() (isMd5Set bool, md5 *hash.Md5Sum, err error)
- func (d *Dictionary) ReadOptionalFileSha1() (isSha1Set bool, sha1 *hash.Sha1Sum, err error)
- func (d *Dictionary) ReadOptionalFileSha256() (isSha256Set bool, sha256 *hash.Sha256Sum, err error)
- type File
- type InfoSectionFormat
- type Version
Constants ¶
const ( PathElement_Dot1 = `.` PathElement_Dot2 = `..` )
Forbidden path elements.
const ( InfoSectionFormat_Unknown = InfoSectionFormat(0) InfoSectionFormat_SingleFile = InfoSectionFormat(1) InfoSectionFormat_MultiFile = InfoSectionFormat(2) )
const ( Version_Unknown = "" Version_One = "1" Version_Two = "2" )
const ( FieldCrc32Sum = "crc32sum" FieldFileTree = "file tree" FieldFiles = "files" FieldLength = "length" FieldMd5Sum = "md5sum" FieldMetaVersion = "meta version" FieldName = "name" FieldPath = "path" FieldPieceLayers = "piece layers" FieldPieceLength = "piece length" FieldPieceRoot = "piece root" FieldPieces = "pieces" FieldPrivate = "private" FieldSha1Sum = "sha1sum" FieldSha256Sum = "sha256sum" )
Fields.
const ( SectionInfo = "info" SectionAnnounce = "announce" SectionAnnounceList = "announce-list" SectionCreationDate = "creation date" SectionComment = "comment" SectionCreatedBy = "created by" SectionEncoding = "encoding" SectionPieceLayers = "piece layers" )
Sections.
const ( TimeFormat1A = "2006-01-02" TimeFormat1B = "02.01.2006" TimeFormat2A = "2006-01-02 MST" TimeFormat2B = "02.01.2006 MST" TimeFormat2C = "2006-01-02 15:04:05" TimeFormat2D = "02.01.2006 15:04:05" TimeFormat3A = "2006-01-02 15:04:05 MST" TimeFormat3B = "02.01.2006 15:04:05 MST" )
const (
SpaceStr = " "
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AnnounceAddress ¶
AnnounceAddress is an announce URL.
func NewAnnounceAddressFromString ¶
func NewAnnounceAddressFromString(s string) (aa *AnnounceAddress, err error)
NewAnnounceAddressFromString parses the string into the object of AnnounceAddress type.
func NewAnnounceAddressListFromStringArray ¶
func NewAnnounceAddressListFromStringArray(sa []string) (aal []AnnounceAddress, err error)
NewAnnounceAddressListFromStringArray parses the string array into the array of objects of AnnounceAddress type.
type Dictionary ¶
type Dictionary []b.DictionaryItem
Dictionary is a "bencoded" dictionary.
func InterfaceAsDictionary ¶
func InterfaceAsDictionary(x any) (d Dictionary, err error)
InterfaceAsDictionary tries to interpret an interface as a dictionary.
func (*Dictionary) FillFileParameters ¶
func (d *Dictionary) FillFileParameters(outNode *ft.FileTreeNode) (err error)
FillFileParameters fills (writes) file parameters into the specified file tree node pointer. The 'outNode' parameter must be a valid pointer. Current dictionary is a dictionary which has an item containing the special dictionary with file parameters.
func (*Dictionary) FindDictionaryItem ¶
func (d *Dictionary) FindDictionaryItem(name string) (item *b.DictionaryItem, err error)
FindDictionaryItem tries to search for a dictionary entry (item) specified by its key (name). On success, the entry is returned.
func (*Dictionary) GetFieldValue ¶
func (d *Dictionary) GetFieldValue(fieldName string) (fv any, err error)
GetFieldValue returns a dictionary's entry specified by its key (name). The difference between this method and 'FindDictionaryItem' is that the latter is a more "low-level" function and is used by other functions.
func (*Dictionary) GetFieldValueAsInt ¶
func (d *Dictionary) GetFieldValueAsInt(fieldName string) (fv int, err error)
GetFieldValueAsInt returns a dictionary's entry specified by its key (name) as int.
func (*Dictionary) GetFieldValueAsString ¶
func (d *Dictionary) GetFieldValueAsString(fieldName string) (fv string, err error)
GetFieldValueAsString returns a dictionary's entry specified by its key (name) as string.
func (*Dictionary) GetFieldValueAsStringArray ¶
func (d *Dictionary) GetFieldValueAsStringArray(fieldName string) (fv []string, err error)
GetFieldValueAsStringArray returns a dictionary's entry specified by its key (name) as a string array.
func (*Dictionary) GuessFormat ¶
func (d *Dictionary) GuessFormat() (format InfoSectionFormat)
GuessFormat tries to guess the format of the dictionary. This method is used only for the 'info' section dictionary and when the BitTorrent file is of the original first version.
func (*Dictionary) GuessVersion ¶
func (d *Dictionary) GuessVersion() (version Version, err error)
GuessVersion tries to guess the version of the dictionary. This method is used only for the 'info' section dictionary.
func (*Dictionary) IsFieldPresent ¶
func (d *Dictionary) IsFieldPresent(fieldName string) (isFieldPresent bool)
IsFieldPresent tries to search for a dictionary entry (item) specified by its key (name). On success, the presence flag is returned.
func (*Dictionary) IsFileParametersNodeV2 ¶
func (d *Dictionary) IsFileParametersNodeV2() bool
IsFileParametersNodeV2 checks whether the dictionary is a special dictionary used for storing file parameters. This approach proves that BitTorrent file format is a nightmare.
func (*Dictionary) ReadFilePath ¶
func (d *Dictionary) ReadFilePath(isf InfoSectionFormat) (filePath []string, err error)
ReadFilePath reads the file path. Beware that depending on the format of the 'info' section, this may be either the full path or the path without the root path. If you are looking for a full path, you should prepend this path with the root path when it is needed. Unfortunately, BitTorrent file format is crazy.
func (*Dictionary) ReadFileSize ¶
func (d *Dictionary) ReadFileSize() (fs int, err error)
ReadFileSize reads the 'length' field of the dictionary.
func (*Dictionary) ReadOptionalFileCrc32 ¶
func (d *Dictionary) ReadOptionalFileCrc32() (isCrc32Set bool, crc32 *hash.Crc32Sum, err error)
ReadOptionalFileCrc32 reads the optional field of the dictionary, CRC32 check sum field.
func (*Dictionary) ReadOptionalFileMd5 ¶
func (d *Dictionary) ReadOptionalFileMd5() (isMd5Set bool, md5 *hash.Md5Sum, err error)
ReadOptionalFileMd5 reads the optional field of the dictionary, MD5 check sum field.
func (*Dictionary) ReadOptionalFileSha1 ¶
func (d *Dictionary) ReadOptionalFileSha1() (isSha1Set bool, sha1 *hash.Sha1Sum, err error)
ReadOptionalFileSha1 reads the optional field of the dictionary, SHA-1 check sum field.
func (*Dictionary) ReadOptionalFileSha256 ¶
func (d *Dictionary) ReadOptionalFileSha256() (isSha256Set bool, sha256 *hash.Sha256Sum, err error)
ReadOptionalFileSha256 reads the optional field of the dictionary, SHA-256 check sum field.
type File ¶
type File struct { // Path elements of the file path. // The last element is the file's name. Path []string // File size in bytes. Size int // Hash sums. HashSum hash.FileHash }
File is information about a single file mentioned in the BitTorrent file.
func (*File) SanitiseFilePath ¶
func (f *File) SanitiseFilePath()
SanitiseFilePath sanitise the file path by removing forbidden elements.
type InfoSectionFormat ¶
type InfoSectionFormat byte
InfoSectionFormat is the format of the 'info' section.