fragment

package
v0.0.0-...-bd9ca74 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fragment manages the fragment cache used to upload files to the server. The fragment cache lets files be uploaded in pieces, and then be copied to tape as a single unit. Files are intended to be uploaded as consecutive pieces, of arbitrary size. If a fragment upload does not complete or has and error, that fragment is deleted, and the upload can try again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileEntry

type FileEntry interface {
	// Return a writer which will append a new block to this file.
	Append() (io.WriteCloser, error)

	// Open the file for reading from the very beginning
	Open() io.ReadCloser

	// Stat returns information about this file
	Stat() Stat

	// Rollback deletes the last block of this file. (i.e. the last
	// segment of data which was Appended)
	Rollback() error

	// Set the creator name for this file.
	SetCreator(name string)

	// Set the expected MD5 sum for the entire file (i.e. over all of
	// its blocks).
	SetMD5(hash []byte)

	// Set the expected SHA256 sum for the entire file (i.e. over all of
	// its blocks).
	SetSHA256(hash []byte)

	// Set the mime-type of this file.
	SetMimeType(mimetype string)

	// Sets an opaque metadata blob which can be assigned to each file.
	SetExtra(extra string)

	// Verify the checksums of this file. Returns true if they match,
	// and false otherwise.
	Verify() (bool, error)
}

A FileEntry represents a single file in the fragment store. A FileEntry presents a collection of operations which can be done on a file, including opening it for Appending, and opening it for reading. (A FileEntry cannot be read or written to directly).

type JSONStore

type JSONStore struct {
	store.Store
}

A JSONStore wraps a Store and provides a store which serializes its items as JSON instead of using streams. It does not cache the results of serialization/deserialization. Since it deals with interface{} instead of readers and writers, a JSONStore does not match the store.Store interface.

func NewJSON

func NewJSON(s store.Store) JSONStore

NewJSON creates a new JSONStore using the provided store for its storage.

func (JSONStore) Create

func (js JSONStore) Create(key string, value interface{}) error

Create is a synonym for Save(). (Why do we have this?) This is here to override js.Store.Create()

func (JSONStore) Open

func (js JSONStore) Open(key string, value interface{}) error

Open the item having the given key and unserialize it into value.

func (JSONStore) Save

func (js JSONStore) Save(key string, value interface{}) error

Save the value val under the given key. It will delete any existing value for the key before doing the save.

type Stat

type Stat struct {
	ID         string
	Size       int64
	NFragments int
	Created    time.Time
	Modified   time.Time
	Creator    string
	MD5        []byte // expected hash for entire file
	SHA256     []byte // expected hash for entire file
	MimeType   string
	Extra      string // arbitrary user defined content
}

Stat contains the metadata for a file entry.

type Store

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

Store wraps a store.Store and provides a fragment cache. This allows files to be uploaded in pieces, "fragments", and then read back as a single unit.

func New

func New(s store.Store) *Store

New creates a new fragment store wrapping a store.Store. Call Load() before using the store.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete deletes a file. It is not an error to delete a file that does not exist.

func (*Store) List

func (s *Store) List() []string

List returns the names of all the stored files. (But not the names of the individual fragment files).

func (*Store) Load

func (s *Store) Load() error

Load initializes the in-memory indexing and caches for the stored file entries. It must be called before using this store.

func (*Store) Lookup

func (s *Store) Lookup(id string) FileEntry

Lookup returns the FileEntry for the given name. It returns nil if there is no FileEntry with that with that id. Returned pointers are not safe to be accessed by more than one goroutine.

func (*Store) New

func (s *Store) New(id string) FileEntry

New creates a new file with the given name and return a pointer to it. The file is not persisted until its first fragment has been written. If the file already exists, nil is returned.

Jump to

Keyboard shortcuts

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