models

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathElement_Dot1 = `.`
	PathElement_Dot2 = `..`
)

Forbidden path elements.

View Source
const (
	InfoSectionFormat_Unknown    = InfoSectionFormat(0)
	InfoSectionFormat_SingleFile = InfoSectionFormat(1)
	InfoSectionFormat_MultiFile  = InfoSectionFormat(2)
)
View Source
const (
	Version_Unknown = ""
	Version_One     = "1"
	Version_Two     = "2"
)
View Source
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.

View Source
const (
	SectionInfo         = "info"
	SectionAnnounce     = "announce"
	SectionAnnounceList = "announce-list"
	SectionCreationDate = "creation date"
	SectionComment      = "comment"
	SectionCreatedBy    = "created by"
	SectionEncoding     = "encoding"
	SectionPieceLayers  = "piece layers"
)

Sections.

View Source
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"
)
View Source
const (
	SpaceStr = " "
)

Variables

This section is empty.

Functions

func ParseBrokenTime

func ParseBrokenTime(s string) (t time.Time, err error)

ParseBrokenTime tries to parse a broken time string.

Types

type AnnounceAddress

type AnnounceAddress struct {
	URL      *url.URL
	RawData  string
	IsBroken bool
}

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.

type Version

type Version = string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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