chunk

package
v0.0.0-...-4ac647c Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timeout")

ErrTimeout is a timeout error

Functions

This section is empty.

Types

type DownloadCallback

type DownloadCallback func(error, []byte)

type Downloader

type Downloader struct {
	Client *drive.Client
	// contains filtered or unexported fields
}

Downloader handles concurrent chunk downloads

func NewDownloader

func NewDownloader(threads int, client *drive.Client) (*Downloader, error)

NewDownloader creates a new download manager

func (*Downloader) Download

func (d *Downloader) Download(req *Request, callback DownloadCallback)

Download starts a new download request

type Item

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

Item represents a chunk in RAM

type Manager

type Manager struct {
	ChunkSize int64
	LoadAhead int
	// contains filtered or unexported fields
}

Manager manages chunks on disk

func NewManager

func NewManager(
	chunkSize int64,
	loadAhead,
	checkThreads int,
	loadThreads int,
	client *drive.Client,
	maxChunks int) (*Manager, error)

NewManager creates a new chunk manager

func (*Manager) GetChunk

func (m *Manager) GetChunk(object *drive.APIObject, offset, size int64, response chan Response)

GetChunk loads one chunk and starts the preload for the next chunks

type QueueEntry

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

type Request

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

Request represents a chunk request

type Response

type Response struct {
	Error error
	Bytes []byte
}

Response represetns a chunk response

type Stack

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

Stack is a thread safe list/stack implementation

func NewStack

func NewStack(maxChunks int) *Stack

NewStack creates a new stack

func (*Stack) Pop

func (s *Stack) Pop() string

Pop pops the first item from the stack

func (*Stack) Push

func (s *Stack) Push(id string)

Push adds a new item to the last position of the stack

func (*Stack) Touch

func (s *Stack) Touch(id string)

Touch moves the specified item to the last position of the stack

type Storage

type Storage struct {
	ChunkSize int64
	MaxChunks int
	// contains filtered or unexported fields
}

Storage is a chunk storage

func NewStorage

func NewStorage(chunkSize int64, maxChunks int) *Storage

NewStorage creates a new storage

func (*Storage) Clear

func (s *Storage) Clear() error

Clear removes all old chunks on disk (will be called on each program start)

func (*Storage) Load

func (s *Storage) Load(id string) []byte

Load a chunk from ram or creates it

func (*Storage) Store

func (s *Storage) Store(id string, bytes []byte) error

Store stores a chunk in the RAM and adds it to the disk storage queue

Jump to

Keyboard shortcuts

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