chunk

package
v0.0.0-...-396ac7b Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

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

Chunk of memory

type DownloadCallback

type DownloadCallback func(error, []byte)

type Downloader

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

Downloader handles concurrent chunk downloads

func NewDownloader

func NewDownloader(threads int, client *drive.Client, storage *Storage, bufferSize int64) (*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 Manager

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

Manager manages chunks on disk

func NewManager

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

NewManager creates a new chunk manager

func (*Manager) GetChunk

func (m *Manager) GetChunk(object *drive.APIObject, offset, size int64) ([]byte, error)

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 RequestID

type RequestID [24]byte

RequestID is the binary identifier for a chunk request

func (RequestID) String

func (id RequestID) String() string

type Response

type Response struct {
	Sequence int
	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) Len

func (s *Stack) Len() int

Len gets the number of items on the stack

func (*Stack) Pop

func (s *Stack) Pop() int

Pop pops the first item from the stack

func (*Stack) Prepend

func (s *Stack) Prepend(items *list.List)

Prepend adds a list to the front of the stack

func (*Stack) Purge

func (s *Stack) Purge(item *list.Element)

Purge an item from the stack

func (*Stack) Push

func (s *Stack) Push(id int) *list.Element

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

func (*Stack) Touch

func (s *Stack) Touch(item *list.Element)

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

type Storage

type Storage struct {
	ChunkFile  *os.File
	ChunkSize  int64
	HeaderSize int64
	MaxChunks  int
	// contains filtered or unexported fields
}

Storage is a chunk storage

func NewStorage

func NewStorage(chunkSize int64, maxChunks int, maxMmapSize int64, chunkFilePath string) (*Storage, error)

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 RequestID) []byte

Load a chunk from ram or creates it

func (*Storage) Store

func (s *Storage) Store(id RequestID, bytes []byte) (err 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