taipei

package module
v0.0.0-...-86a333f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2016 License: BSD-3-Clause Imports: 20 Imported by: 3

README

Taipei Torrent Stripped Library

This is a simple BitTorrent library stripped from Taipei-Torrent

Build Status

See original README.

Why library?

I use this in my xltask project, for validating .torrent file, and verifying file contents.

Instructions

  1. Use go get

     go get -v -u github.com/zyxar/taipei
    
  2. Use git

     git clone https://github.com/zyxar/taipei
     cd taipei
     go install
    
  3. Documentation

See godoc

Documentation

Overview

Compute missing pieces for a torrent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPiece

func CheckPiece(fs FileStore, totalLength int64, m *MetaInfo, pieceIndex int) (good bool, err error)

func CheckPieces

func CheckPieces(fs FileStore, totalLength int64, m *MetaInfo) (good, bad int, err error)

func ComputePieceSum

func ComputePieceSum(fs FileStore, totalLength int64, pieceLength int64, pieceIndex int) (sum []byte, err error)

func ComputeSums

func ComputeSums(fs FileStore, totalLength int64, pieceLength int64) (sums []byte, err error)

ComputeSums reads the file content and computes the SHA1 hash for each piece. Spawns parallel goroutines to compute the hashes, since each computation takes ~30ms.

func ProgressBar

func ProgressBar(i, j int) string

func SetEcho

func SetEcho(b bool)

func VerifyContent

func VerifyContent(m *MetaInfo, root string) (bool, error)

func VerifyFull

func VerifyFull(m *MetaInfo, root string) (bool, error)

func VerifyPartial

func VerifyPartial(m *MetaInfo, root string) (bool, error)

func VerifySingle

func VerifySingle(m *MetaInfo, root string) (bool, error)

Types

type Bitset

type Bitset struct {
	// contains filtered or unexported fields
}

func NewBitset

func NewBitset(n int) *Bitset

func NewBitsetFromBytes

func NewBitsetFromBytes(n int, data []byte) *Bitset

Creates a new bitset from a given byte stream. Returns nil if the data is invalid in some way.

func (*Bitset) AndNot

func (b *Bitset) AndNot(b2 *Bitset)

func (*Bitset) Bytes

func (b *Bitset) Bytes() []byte

func (*Bitset) Clear

func (b *Bitset) Clear(index int)

func (*Bitset) FindNextClear

func (b *Bitset) FindNextClear(index int) int

TODO: Make this fast

func (*Bitset) FindNextSet

func (b *Bitset) FindNextSet(index int) int

TODO: Make this fast

func (*Bitset) IsEndValid

func (b *Bitset) IsEndValid() bool

func (*Bitset) IsSet

func (b *Bitset) IsSet(index int) bool

func (*Bitset) Set

func (b *Bitset) Set(index int)

type FileDict

type FileDict struct {
	Length int64
	Path   []string
	Md5sum string
}

func (FileDict) String

func (f FileDict) String() string

type FileStore

type FileStore interface {
	io.ReaderAt
	io.WriterAt
	io.Closer
}

func MkFileStore

func MkFileStore(fd *os.File) (fs FileStore, err error)

func NewFileStore

func NewFileStore(info *InfoDict, storePath string) (f FileStore, totalSize int64, err error)

type InfoDict

type InfoDict struct {
	PieceLength int64 "piece length"
	Pieces      string
	Private     int64
	Name        string
	// Single File Mode
	Length int64
	Md5sum string
	// Multiple File mode
	Files []FileDict
}

func (InfoDict) String

func (i InfoDict) String() string

type Magnet

type Magnet struct {
	InfoHashes []string
}

type MetaInfo

type MetaInfo struct {
	Info         InfoDict
	InfoHash     string
	Announce     string
	CreationDate string "creation date"
	Comment      string
	CreatedBy    string "created by"
	Encoding     string
}

func DecodeMetaInfo

func DecodeMetaInfo(p []byte) (metaInfo *MetaInfo, err error)

func GetMetaInfo

func GetMetaInfo(torrent string) (metaInfo *MetaInfo, err error)

func Iconv

func Iconv(in *MetaInfo) *MetaInfo

func (MetaInfo) String

func (m MetaInfo) String() string

Jump to

Keyboard shortcuts

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