예제 #1
0
func Example_fileReader() {
	var (
		t torrent.Torrent
		f torrent.File
	)
	r := t.NewReader()
	defer r.Close()
	// Access the parts of the torrent pertaining to f. Data will be
	// downloaded as required, per the configuration of the torrent.Reader.
	_ = missinggo.NewSectionReadSeeker(r, f.Offset(), f.Length())
}
예제 #2
0
// NewFileReader sets up a torrent file for streaming reading.
func NewFileReader(c Client, f *torrent.File) (SeekableContent, error) {
	// We read ahead 1% of the file continuously.
	var readahead = f.Length() / 100

	reader := c.Torrent.NewReader()
	reader.SetReadahead(readahead)
	reader.SetResponsive()
	_, err := reader.Seek(f.Offset(), os.SEEK_SET)

	return &FileEntry{
		File:   f,
		Reader: reader,
	}, err
}
예제 #3
0
// NewFileReader sets up a torrent file for streaming reading.
func NewFileReader(c Client, f torrent.File) (SeekableContent, error) {
	// We read ahead 1% of the file continuously.
	var readahead = f.Length() / 100

	// We begin by prioritizing 5% of the beginning of the file.
	f.PrioritizeRegion(f.Offset(), readahead*5)

	reader := c.Torrent.NewReader()
	reader.SetReadahead(readahead)
	reader.SetResponsive()
	_, err := reader.Seek(f.Offset(), os.SEEK_SET)

	return &FileEntry{
		File:   &f,
		Reader: reader,
	}, err
}
예제 #4
0
func (this *DownloaderService) DownloadPlay(downloader_id, file_path string) (sc SeekAbleContent, path string, err error) {
	log.Println("DownloadPlay: downloader_id -> ", downloader_id, " file_path -> ", file_path)
	this.RLock()
	defer this.RUnlock()

	var downloader = &downloader.Downloader{}
	var file torrent.File

	downloader, err = this.df.Get(downloader_id)
	if err != nil {
		return
	}

	file, err = downloader.GetFileFoPlay(file_path)
	if err != nil {
		return
	}

	sc, err = NewReader(downloader.Torrent, file)
	if err != nil {
		return
	}
	return sc, file.DisplayPath(), nil
}
예제 #5
0
// NewFileReader sets up a torrent file for streaming reading.
func NewFileReader(f *torrent.File) (SeekableContent, error) {
	// Start download
	f.Download()

	torrent := f.Torrent()
	reader := torrent.NewReader()

	// Read ahead 10mb
	reader.SetReadahead(1024 * 1024 * 10)
	reader.SetResponsive()
	_, err := reader.Seek(f.Offset(), os.SEEK_SET)

	return &FileEntry{
		File:   f,
		Reader: reader,
		N:      f.Length(),
	}, err
}
예제 #6
0
func (e *Engine) GetTorrentPercent(file *torrent.File) float32 {
	t := e.upsertTorrent(file.Torrent())
	return t.Percent
}