filebox

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeUnknown Type = 0

	TypeBase64 = 1
	TypeUrl    = 2
	TypeQRCode = 3
	TypeBuffer = 4
	TypeFile   = 5
	TypeStream = 6
	TypeUuid   = 7
)

Variables

View Source
var (
	// ErrToJSON err to json
	ErrToJSON = errors.New("FileBox.toJSON() only support TypeUrl,TypeQRCode,TypeBase64, TypeUuid")
	// ErrNoBase64Data no base64 data
	ErrNoBase64Data = errors.New("no Base64 data")
	// ErrNoUrl no url
	ErrNoUrl = errors.New("no url")
	// ErrNoPath no path
	ErrNoPath = errors.New("no path")
	// ErrNoQRCode no QR Code
	ErrNoQRCode = errors.New("no QR Code")
	// ErrNoUuid no uuid
	ErrNoUuid = errors.New("no uuid")
)

Functions

func SetUuidLoader

func SetUuidLoader(loader UuidLoader)

SetUuidLoader set uuid loader

func SetUuidSaver

func SetUuidSaver(saver UuidSaver)

SetUuidSaver set uuid saver

Types

type FileBox

type FileBox struct {
	Name string
	// contains filtered or unexported fields
}

FileBox struct

func FromBase64

func FromBase64(encode string, options ...Option) *FileBox

FromBase64 create FileBox from Base64

func FromFile

func FromFile(path string, options ...Option) *FileBox

FromFile create FileBox from file

func FromJSON

func FromJSON(s string) *FileBox

FromJSON create FileBox from JSON

func FromQRCode

func FromQRCode(qrCode string, options ...Option) *FileBox

FromQRCode create FileBox from QRCode

func FromStream

func FromStream(reader io.Reader, options ...Option) *FileBox

FromStream from io.Reader

func FromUrl

func FromUrl(urlString string, options ...Option) *FileBox

FromUrl create FileBox from url

func FromUuid

func FromUuid(uuid string, options ...Option) *FileBox

func (*FileBox) Error

func (fb *FileBox) Error() error

Error ret err

func (*FileBox) MetaData

func (fb *FileBox) MetaData() map[string]interface{}

MetaData get metadata

func (*FileBox) Size

func (fb *FileBox) Size()

func (*FileBox) String

func (fb *FileBox) String() string

String ...

func (*FileBox) ToBase64

func (fb *FileBox) ToBase64() (string, error)

ToBase64 to base64 string

func (*FileBox) ToBytes

func (fb *FileBox) ToBytes() ([]byte, error)

ToBytes to bytes

func (*FileBox) ToDataURL

func (fb *FileBox) ToDataURL() (string, error)

ToDataURL to dataURL

func (*FileBox) ToFile

func (fb *FileBox) ToFile(filePath string, overwrite bool) error

ToFile save to file

func (*FileBox) ToJSON

func (fb *FileBox) ToJSON() (string, error)

ToJSON to json string

func (*FileBox) ToQRCode

func (fb *FileBox) ToQRCode() (string, error)

ToQRCode to QRCode

func (*FileBox) ToReader

func (fb *FileBox) ToReader() (io.Reader, error)

ToReader to io.Reader

func (*FileBox) ToUuid

func (fb *FileBox) ToUuid() (string, error)

ToUuid to uuid

func (*FileBox) Type

func (fb *FileBox) Type() Type

Type get type

type Option

type Option func(options *Options)

func WithMd5

func WithMd5(md5 string) Option

WithMd5 set md5

func WithMetadata

func WithMetadata(metadata map[string]interface{}) Option

WithMetadata set metadata

func WithName

func WithName(name string) Option

WithName set name

func WithOptions

func WithOptions(o Options) Option

func WithSize

func WithSize(size int64) Option

WithSize set size

type Options

Options ...

type OptionsBase64

type OptionsBase64 struct {
	Base64 string `json:"base64"`
}

OptionsBase64 base64

type OptionsCommon

type OptionsCommon struct {
	Name     string                 `json:"name"`
	Metadata map[string]interface{} `json:"metadata"`
	BoxType  Type                   `json:"type"`
	// Deprecated
	BoxTypeDeprecated Type   `json:"boxType"`
	Size              int64  `json:"size"`
	Md5               string `json:"md5"`
}

OptionsCommon common options

type OptionsQRCode

type OptionsQRCode struct {
	QrCode string `json:"qrCode"`
}

OptionsQRCode QRCode

type OptionsUrl

type OptionsUrl struct {
	RemoteUrl string      `json:"url"`
	Headers   http.Header `json:"headers"`
}

OptionsUrl url

type OptionsUuid

type OptionsUuid struct {
	Uuid string `json:"uuid"`
}

OptionsUuid uuid

type Type

type Type uint8

func (Type) String

func (i Type) String() string

type UuidLoader

type UuidLoader func(uuid string) (io.Reader, error)

UuidLoader uuid loader

type UuidSaver

type UuidSaver func(reader io.Reader) (uuid string, err error)

UuidSaver uuid saver

Jump to

Keyboard shortcuts

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