hidrive

package
v1.59.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 30 Imported by: 4

Documentation

Overview

Package hidrive provides an interface to the HiDrive object storage system.

Index

Constants

View Source
const (
	// MaximumUploadBytes represents the maximum amount of bytes
	// a single upload-operation will support.
	MaximumUploadBytes = 2147483647 // = 2GiB - 1

)

Variables

View Source
var (
	// Unsorted disables sorting and can therefore not be combined with other values.
	Unsorted = []SortByField{"none"}
	// DefaultSorted does not specify how to sort and
	// therefore implies the default sort order.
	DefaultSorted = []SortByField{}
)
View Source
var (

	// ErrorFileExists is returned when a query tries to create a file
	// that already exists.
	ErrorFileExists = errors.New("destination file already exists")
)

Functions

func NewFs

func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, error)

NewFs creates a new file system from the path.

Types

type CopyOrMoveOperationType

type CopyOrMoveOperationType int

CopyOrMoveOperationType represents the possible types of copy- and move-operations.

const (
	MoveOriginal CopyOrMoveOperationType = iota
	CopyOriginal
	CopyOriginalPreserveModTime
)

possible values for CopyOrMoveOperationType

type Fs

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

Fs represents a remote hidrive.

func (*Fs) Copy

func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error)

Copy src to this remote using server-side copy operations.

It returns the destination Object and a possible error.

This returns fs.ErrorCantCopy if the operation cannot be performed.

NOTE: If an error occurs when copying the Object, any parent-directories already created will NOT be deleted again.

NOTE: This operation will expand sparse areas in the content of the source-Object to blocks of 0-bytes in the destination-Object.

func (*Fs) DirMove

func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string) error

DirMove moves from src at srcRemote to this remote at dstRemote using server-side move operations.

This returns fs.ErrorCantCopy if the operation cannot be performed. This returns fs.ErrorDirExists if the destination already exists.

NOTE: If an error occurs when moving the directory, any parent-directories already created will NOT be deleted again.

func (*Fs) Features

func (f *Fs) Features() *fs.Features

Features returns the optional features of this Fs.

func (*Fs) Hashes

func (f *Fs) Hashes() hash.Set

Hashes returns the supported hash sets.

func (*Fs) List

func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error)

List the objects and directories in dir into entries. The entries can be returned in any order, but should be for a complete directory.

dir should be "" to list the root, and should not have trailing slashes.

This returns fs.ErrorDirNotFound if the directory is not found.

func (*Fs) Mkdir

func (f *Fs) Mkdir(ctx context.Context, dir string) error

Mkdir creates the directory if it does not exist.

This will create any missing parent directories.

NOTE: If an error occurs while the parent directories are being created, any directories already created will NOT be deleted again.

func (*Fs) Move

func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, error)

Move src to this remote using server-side move operations.

It returns the destination Object and a possible error.

This returns fs.ErrorCantMove if the operation cannot be performed.

NOTE: If an error occurs when moving the Object, any parent-directories already created will NOT be deleted again.

NOTE: This operation will expand sparse areas in the content of the source-Object to blocks of 0-bytes in the destination-Object.

func (*Fs) Name

func (f *Fs) Name() string

Name returns the name of the remote (as passed into NewFs).

func (*Fs) NewObject

func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error)

NewObject finds the Object at remote.

If remote points to a directory then it returns fs.ErrorIsDir. If it can not be found it returns the error fs.ErrorObjectNotFound.

func (*Fs) Precision

func (f *Fs) Precision() time.Duration

Precision returns the precision of this Fs.

func (*Fs) Purge

func (f *Fs) Purge(ctx context.Context, dir string) error

Purge removes the directory and all of its contents.

This returns fs.ErrorDirectoryNotEmpty if the directory is not empty.

func (*Fs) Put

func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)

Put the contents of the io.Reader into the remote path with the modTime given of the given size. The existing or new object is returned.

A new object may have been created or an existing one accessed even if an error is returned, in which case both the object and the error will be returned.

func (*Fs) PutStream

func (f *Fs) PutStream(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)

PutStream uploads the contents of the io.Reader to the remote path with the modTime given of indeterminate size. The existing or new object is returned.

A new object may have been created or an existing one accessed even if an error is returned, in which case both the object and the error will be returned.

func (*Fs) PutUnchecked

func (f *Fs) PutUnchecked(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)

PutUnchecked the contents of the io.Reader into the remote path with the modTime given of the given size. This guarantees that existing objects will not be overwritten. The new object is returned.

This will produce an error if an object already exists at that path.

In case the upload fails and an object has been created, this will try to delete the object at that path. In case the failed upload could not be deleted, both the object and the (upload-)error will be returned.

func (*Fs) Rmdir

func (f *Fs) Rmdir(ctx context.Context, dir string) error

Rmdir removes the directory if empty.

This returns fs.ErrorDirNotFound if the directory is not found. This returns fs.ErrorDirectoryNotEmpty if the directory is not empty.

func (*Fs) Root

func (f *Fs) Root() string

Root returns the name of the remote (as passed into NewFs).

func (*Fs) String

func (f *Fs) String() string

String returns a string-representation of this Fs.

type MemberType

type MemberType string

MemberType represents the possible types of entries a directory can contain.

const (
	AllMembers       MemberType = "all"
	NoMembers        MemberType = "none"
	DirectoryMembers MemberType = api.HiDriveObjectTypeDirectory
	FileMembers      MemberType = api.HiDriveObjectTypeFile
	SymlinkMembers   MemberType = api.HiDriveObjectTypeSymlink
)

possible values for MemberType

type Object

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

Object describes a hidrive object.

Will definitely have the remote-path but may lack meta-information.

func (*Object) Fs

func (o *Object) Fs() fs.Info

Fs returns the parent Fs.

func (*Object) Hash

func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error)

Hash returns the selected checksum of the file. If no checksum is available it returns "".

func (*Object) ID

func (o *Object) ID() string

ID returns the ID of the Object if known, or "" if not.

func (*Object) ModTime

func (o *Object) ModTime(ctx context.Context) time.Time

ModTime returns the modification time of the object.

func (*Object) Open

func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error)

Open an object for reading.

func (*Object) Remote

func (o *Object) Remote() string

Remote returns the remote path.

func (*Object) Remove

func (o *Object) Remove(ctx context.Context) error

Remove an object.

func (*Object) SetModTime

func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error

SetModTime sets the metadata on the object to set the modification date.

func (*Object) Size

func (o *Object) Size() int64

Size returns the size of an object in bytes.

func (*Object) Storable

func (o *Object) Storable() bool

Storable says whether this object can be stored.

func (*Object) String

func (o *Object) String() string

String returns a string-representation of this Object.

func (*Object) Update

func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error

Update the existing object with the contents of the io.Reader, modTime and size.

For unknown-sized contents (indicated by src.Size() == -1) this will try to properly upload it in multiple chunks.

type OnExistAction

type OnExistAction string

OnExistAction represents possible actions the API should take, when a request tries to create a path that already exists.

const (
	// IgnoreOnExist instructs the API not to execute
	// the request in case of a conflict, but to return an error.
	IgnoreOnExist OnExistAction = "ignore"
	// AutoNameOnExist instructs the API to automatically rename
	// any conflicting request-objects.
	AutoNameOnExist OnExistAction = "autoname"
	// OverwriteOnExist instructs the API to overwrite any conflicting files.
	// This can only be used, if the request operates on files directly.
	// (For example when moving/copying a file.)
	// For most requests this action will simply be ignored.
	OverwriteOnExist OnExistAction = "overwrite"
)

possible values for OnExistAction

type Options

type Options struct {
	EndpointAPI                 string               `config:"endpoint"`
	OptionalMemberCountDisabled bool                 `config:"disable_fetching_member_count"`
	UploadChunkSize             fs.SizeSuffix        `config:"chunk_size"`
	UploadCutoff                fs.SizeSuffix        `config:"upload_cutoff"`
	UploadConcurrency           int64                `config:"upload_concurrency"`
	Enc                         encoder.MultiEncoder `config:"encoding"`
	RootPrefix                  string               `config:"root_prefix"`
	ScopeAccess                 string               `config:"scope_access"`
	ScopeRole                   string               `config:"scope_role"`
}

Options defines the configuration for this backend.

type SortByField

type SortByField string

SortByField represents possible fields to sort entries of a directory by.

const (
	SortByName                 SortByField = "name"
	SortByModTime              SortByField = "mtime"
	SortByObjectType           SortByField = "type"
	SortBySize                 SortByField = "size"
	SortByNameDescending       SortByField = SortByField(descendingSort) + SortByName
	SortByModTimeDescending    SortByField = SortByField(descendingSort) + SortByModTime
	SortByObjectTypeDescending SortByField = SortByField(descendingSort) + SortByObjectType
	SortBySizeDescending       SortByField = SortByField(descendingSort) + SortBySize
)

possible values for SortByField

Directories

Path Synopsis
Package api has type definitions and code related to API-calls for the HiDrive-API.
Package api has type definitions and code related to API-calls for the HiDrive-API.
Package hidrivehash implements the HiDrive hashing algorithm which combines SHA-1 hashes hierarchically to a single top-level hash.
Package hidrivehash implements the HiDrive hashing algorithm which combines SHA-1 hashes hierarchically to a single top-level hash.

Jump to

Keyboard shortcuts

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