device

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParentDirNotExists = errors.New("FileItem's Parent Directory does not exist")
	ErrEmptyData          = errors.New("Passed Buffer is Empty")
)
View Source
var (
	// Determined/Provided Paths
	Home      Folder // ApplicationDocumentsDir on Mobile, HOME_DIR on Desktop
	Support   Folder // AppSupport Directory
	Temporary Folder // AppCache Directory

	// Calculated Paths
	Database   Folder // Device DB Folder
	Downloads  Folder // Temporary Directory on Mobile for Export, Downloads on Desktop
	Wallet     Folder // Encrypted Storage Directory
	ThirdParty Folder // Sub-Directory of Support, used for Textile

	// Path Manipulation Errors
	ErrDuplicateFilePathOption    = errors.New("Duplicate file path option")
	ErrPrefixSuffixSetWithReplace = errors.New("Prefix or Suffix set with Replace.")
	ErrSeparatorLength            = errors.New("Separator length must be 1.")
	ErrNoFileNameSet              = errors.New("File name was not set by options.")

	// Device ID Errors
	ErrEmptyDeviceID = errors.New("Device ID cannot be empty")
	ErrMissingEnvVar = errors.New("Cannot set EnvVariable with empty value")

	// Directory errors
	ErrDirectoryInvalid = errors.New("Directory Type is invalid")
	ErrDirectoryUnset   = errors.New("Directory path has not been set")
	ErrDirectoryJoin    = errors.New("Failed to join directory path")
)

Functions

func DefaultUrlMIME added in v0.18.2

func DefaultUrlMIME() *types.MIME

** ─────────────────────────────────────────────────────── ** ─── MIME Management ─────────────────────────────────── ** ─────────────────────────────────────────────────────── DefaultUrlMIME is the standard MIME type for URLs

func Exists

func Exists(fileName string) bool

Exists checks if a file exists.

func Ext added in v0.18.2

func Ext(m *types.MIME) string

Ext Method adjusts extension for JPEG

Header returns the header of the FileItem

func IsAudio added in v0.18.2

func IsAudio(m *types.MIME) bool

IsAudio Checks if Mime is Audio

func IsFile

func IsFile(fileName string) bool

IsFile returns true if the given path is a file

func IsImage added in v0.18.2

func IsImage(m *types.MIME) bool

IsImage Checks if Mime is Image

func IsMedia added in v0.18.2

func IsMedia(m *types.MIME) bool

IsMedia Checks if Mime is any media

func IsPDF added in v0.18.2

func IsPDF(m *types.MIME) bool

IsPDF Checks if Mime is PDF

func IsUrl added in v0.18.2

func IsUrl(m *types.MIME) bool

IsUrl Checks if Path is a URL

func IsVideo added in v0.18.2

func IsVideo(m *types.MIME) bool

IsVideo Checks if Mime is Video

func NewFileItem added in v0.18.2

func NewFileItem(path string, tbuf []byte) (*types.Payload_Item, error)

NewFileItem creates a new transfer file item

func NewMime added in v0.18.2

func NewMime(path string) (*types.MIME, error)

NewMime creates a new MIME type from Path

func NewThumbnail added in v0.18.2

func NewThumbnail(path string, tbuf []byte, mime *types.MIME, ch chan *types.Thumbnail)

NewThumbnail creates a new thumbnail for the given file

func PermitsThumbnail added in v0.18.2

func PermitsThumbnail(m *types.MIME) bool

PermitsThumbnail Checks if Mime Type Allows Thumbnail Generation. Image, Video, Audio, and PDF are allowed.

func SetPathFromFolder added in v0.18.2

func SetPathFromFolder(f *types.FileItem, folder Folder) (string, error)

SetPathFromFolder sets the path of the FileItem

func ToTransferItem added in v0.18.2

func ToTransferItem(f *types.FileItem) *types.Payload_Item

ToTransferItem Returns Transfer for FileItem

Types

type FilePathOptFunc

type FilePathOptFunc func(path string) FilePathOption

FilePathOptFunc is a function that returns a FilePathOption.

var WithPrefix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypePrefix,
		value:           path,
	}
}

WithPrefix sets the prefix for the file path.

var WithReplace FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeReplace,
		value:           path,
	}
}

WithReplace sets the replace string for the file path.

var WithSeparator FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSeparator,
		value:           path,
	}
}

WithSeparator sets the separator for the file path.

var WithSuffix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSuffix,
		value:           path,
	}
}

WithSuffix sets the suffix for the file path.

type FilePathOption

type FilePathOption interface {
	Apply() *filePathOptions
}

FilePathOption is a function option for FilePath.

type Folder

type Folder string

func (Folder) Create

func (f Folder) Create(fileName string) (*os.File, error)

Create creates a file.

func (Folder) CreateFolder

func (f Folder) CreateFolder(dirName string) (Folder, error)

CreateFolder creates a folder.

func (Folder) Delete

func (f Folder) Delete(fileName string) error

Delete removes a file or a folder.

func (Folder) Exists

func (f Folder) Exists(fileName string) bool

Exists checks if a file exists.

func (Folder) GenPath

func (f Folder) GenPath(path string, opts ...FilePathOption) (string, error)

GenPath generates a path from a folder and a file name.

func (Folder) JoinPath

func (f Folder) JoinPath(ps ...string) string

JoinPath joins a folder and a file name.

func (Folder) MkdirAll

func (f Folder) MkdirAll() error

MkdirAll creates a directory and all its parents.

func (Folder) Path

func (f Folder) Path() string

Path returns the path of the folder.

func (Folder) ReadFile

func (f Folder) ReadFile(fileName string) ([]byte, error)

ReadFile reads a file.

func (Folder) WriteFile

func (f Folder) WriteFile(fileName string, data []byte) error

WriteFile writes a file.

type Role added in v0.18.2

type Role int

Role is the type of the node (Client, Highway)

const (
	// StubMode_LIB is the Node utilized by Mobile and Web Clients
	Role_UNSPECIFIED Role = iota

	// StubMode_CLI is the Node utilized by CLI Clients
	Role_TEST

	// Role_MOTOR is for a Motor Node
	Role_MOTOR

	// Role_HIGHWAY is for a Highway Node
	Role_HIGHWAY
)

func (Role) IsHighway added in v0.18.2

func (m Role) IsHighway() bool

Highway returns true if the node has a highway stub.

func (Role) IsMotor added in v0.18.2

func (m Role) IsMotor() bool

Motor returns true if the node has a client.

func (Role) Prefix added in v0.18.2

func (m Role) Prefix() string

Prefix returns golog prefix for the node.

Jump to

Keyboard shortcuts

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