torrentfile

package
v0.0.0-...-101a212 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package torrentfile parses torrent files or magnet links.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Length   int    // length in bytes
	FullPath string // download path
	SHA1Hash string // optional for final validation
	MD5Hash  string // optional for final validation
}

File contains metadata about the final downloaded files, namely their path and file length.

type TorrentFile

type TorrentFile struct {
	TrackerURLs []string   // tracker URLs (from announce-list, announce or magnet link tr)
	InfoHash    [20]byte   // SHA-1 hash of the entire info field, uniquely identifies the torrent
	PieceHashes [][20]byte // SHA-1 hashes of each file piece
	PieceLength int        // number of bytes per piece
	Files       []File     // in the 1 file case, this will only have one element
	TotalLength int        // calculated as the sum of all files
	DisplayName string     // human readable display name (.torrent filename or magnet link dn)
}

TorrentFile represents the contents of a .torrent file, reformatted for ease of use in the download process.

The InfoHash is generated via SHA-1 from the entire Info field of the file.

The 20-byte SHA1 hashes are formatted into a slice of 20-byte arrays for easy comparison with pieces downloaded from a peer.

func New

func New(source string) (TorrentFile, error)

New returns a new TorrentFile.

If the source is a .torrent file, it will be ready for use.

If the source is a magnet link, metadata will need to be acquired from peers already in the swarm, then added using TorrentFile.AppendMetadata()

func (*TorrentFile) AppendMetadata

func (t *TorrentFile) AppendMetadata(metadata []byte) error

AppendMetadata adds the metadata (aka the info dictionary of a torrent file). It must be called after torrentfile.New() is invoked with a magnet link source with the metadata acquired from a peer in the swarm.

Jump to

Keyboard shortcuts

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