socfs

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const BinaryMessageResponseType = 0
View Source
const ThumbnailSuffix = "#thumbnail.jpeg"
View Source
const ThumbnailWidth = 160

Variables

View Source
var DefaultThumbnailer = ThumbnailerGroup{}
View Source
var ErrNotSupported = errors.New("Not supported format")

Functions

func ContentTypeByPath

func ContentTypeByPath(s string) string

func NewPromise

func NewPromise[T any]() *promise[T]

func NewWritableDirFS

func NewWritableDirFS(path string) *writableDirFS

Types

type CachedThumbnailer

type CachedThumbnailer struct {
	CacheDir      string
	SupportedFunc func(typ string) bool
	GenerateFunc  func(ctx context.Context, f fs.FS, src, dst string) error
	// contains filtered or unexported fields
}

func NewImageThumbnailer

func NewImageThumbnailer(cacheDir string) *CachedThumbnailer

func NewVideoThumbnailer

func NewVideoThumbnailer(cacheDir, ffmpegPath string) *CachedThumbnailer

func (*CachedThumbnailer) GetThumbnail

func (t *CachedThumbnailer) GetThumbnail(ctx context.Context, f fs.FS, src, typ string, opt any) (*Thumbnail, error)

func (*CachedThumbnailer) Supported

func (t *CachedThumbnailer) Supported(typ string) bool

type CreateFS added in v0.1.3

type CreateFS interface {
	Create(path string) (io.WriteCloser, error)
}

type FSCapability

type FSCapability struct {
	Read   bool `json:"read"`
	Write  bool `json:"write"`
	Create bool `json:"create"`
	Remove bool `json:"remove"`
}

type FSClient

type FSClient struct {
	MaxReadSize int
	Timeout     time.Duration
	// contains filtered or unexported fields
}

FSClient implements fs.FS

func NewFSClient

func NewFSClient(sendFunc func(req *FileOperationRequest) error) *FSClient

func (*FSClient) Abort

func (c *FSClient) Abort() error

Abort all requests

func (*FSClient) Create

func (c *FSClient) Create(name string) (io.WriteCloser, error)

func (*FSClient) HandleMessage

func (c *FSClient) HandleMessage(data []byte, isjson bool) error

func (*FSClient) Mkdir added in v0.1.3

func (c *FSClient) Mkdir(name string, mode fs.FileMode) error

func (*FSClient) Open

func (c *FSClient) Open(name string) (fs.File, error)

fs.FS

func (*FSClient) OpenDir

func (c *FSClient) OpenDir(name string) (fs.ReadDirFile, error)

func (*FSClient) OpenWriter

func (c *FSClient) OpenWriter(name string, flag int) (io.WriteCloser, error)

func (*FSClient) ReadDir

func (c *FSClient) ReadDir(name string) ([]fs.DirEntry, error)

fs.ReadDirFS

func (*FSClient) ReadDirRange

func (c *FSClient) ReadDirRange(name string, pos, limit int) ([]fs.DirEntry, error)

func (*FSClient) Remove

func (c *FSClient) Remove(name string) error

func (*FSClient) Rename added in v0.1.3

func (c *FSClient) Rename(name string, newName string) error

func (*FSClient) Stat

func (c *FSClient) Stat(name string) (fs.FileInfo, error)

fs.StatFS

func (*FSClient) Truncate

func (c *FSClient) Truncate(name string, size int64) error

type FSServer

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

func NewFSServer

func NewFSServer(fsys fs.FS, parallels int) *FSServer

func (*FSServer) FSCaps added in v0.1.3

func (s *FSServer) FSCaps() *FSCapability

func (*FSServer) HandleMessage

func (h *FSServer) HandleMessage(ctx context.Context, data []byte, isjson bool, writer func(*FileOperationResult) error) error

func (*FSServer) HanldeFileOp

func (h *FSServer) HanldeFileOp(op *FileOperationRequest) (any, error)

type FileEntry

type FileEntry struct {
	Type        string `json:"type"`
	FileName    string `json:"name"`
	FileSize    int64  `json:"size"`
	UpdatedTime int64  `json:"updatedTime,omitempty"`
	CreatedTime int64  `json:"createdTime,omitempty"`
	Writable    bool   `json:"writable,omitempty"`

	Metadata map[string]any `json:"metadata,omitempty"`
}

func NewFileEntry

func NewFileEntry(info os.FileInfo, fswritable bool) *FileEntry

func (*FileEntry) IsDir

func (f *FileEntry) IsDir() bool

func (*FileEntry) ModTime

func (f *FileEntry) ModTime() time.Time

func (*FileEntry) Mode

func (f *FileEntry) Mode() fs.FileMode

func (*FileEntry) Name

func (f *FileEntry) Name() string

func (*FileEntry) SetMetaData

func (f *FileEntry) SetMetaData(key string, value any)

func (*FileEntry) Size

func (f *FileEntry) Size() int64

func (*FileEntry) Sys

func (f *FileEntry) Sys() any

type FileOperationRequest

type FileOperationRequest struct {
	Op    string `json:"op"`
	RID   any    `json:"rid,omitempty"`
	Path  string `json:"path,omitempty"`
	Path2 string `json:"path2,omitempty"`
	Pos   int64  `json:"p,omitempty"`
	Len   int    `json:"l,omitempty"`
	Buf   []byte `json:"b,omitempty"`
}

func (*FileOperationRequest) ToBytes

func (r *FileOperationRequest) ToBytes() []byte

type FileOperationResult

type FileOperationResult struct {
	RID   any             `json:"rid,omitempty"`
	Data  json.RawMessage `json:"data,omitempty"`
	Error string          `json:"error,omitempty"`
	Buf   []byte          `json:"b,omitempty"`
}

func (*FileOperationResult) IsJSON

func (r *FileOperationResult) IsJSON() bool

func (*FileOperationResult) ToBytes

func (r *FileOperationResult) ToBytes() []byte

type MkdirFS added in v0.1.3

type MkdirFS interface {
	Mkdir(name string, mode fs.FileMode) error
}

type OpenDirFS

type OpenDirFS interface {
	OpenDir(name string) (fs.ReadDirFile, error)
}

type OpenWriterFS added in v0.1.3

type OpenWriterFS interface {
	OpenWriter(name string, flag int) (io.WriteCloser, error)
}

type RealPathResolver

type RealPathResolver interface {
	RealPath(string) string
}

type RemoveFS added in v0.1.3

type RemoveFS interface {
	Remove(name string) error
}

type RenameFS added in v0.1.3

type RenameFS interface {
	Rename(name string, newName string) error
}

type Thumbnail

type Thumbnail struct {
	Type string
	Path string
}

type Thumbnailer

type Thumbnailer interface {
	Supported(typ string) bool
	GetThumbnail(ctx context.Context, f fs.FS, path, typ string, opt any) (*Thumbnail, error)
}

type ThumbnailerGroup

type ThumbnailerGroup struct {
	Thumbnailers []Thumbnailer
}

func (ThumbnailerGroup) GetThumbnail

func (g ThumbnailerGroup) GetThumbnail(ctx context.Context, f fs.FS, path, typ string, opt any) (*Thumbnail, error)

func (*ThumbnailerGroup) Register

func (g *ThumbnailerGroup) Register(t Thumbnailer)

func (ThumbnailerGroup) Supported

func (g ThumbnailerGroup) Supported(typ string) bool

type TruncateFS added in v0.1.3

type TruncateFS interface {
	Truncate(name string, size int64) error
}

type WrappedFS added in v0.1.3

type WrappedFS struct {
	fs.FS
	// contains filtered or unexported fields
}

func WrapFS

func WrapFS(fsys fs.FS) *WrappedFS

func (*WrappedFS) Capability added in v0.1.3

func (w *WrappedFS) Capability() *FSCapability

func (*WrappedFS) Create added in v0.1.3

func (w *WrappedFS) Create(name string) (io.WriteCloser, error)

func (*WrappedFS) Mkdir added in v0.1.3

func (w *WrappedFS) Mkdir(path string, mode fs.FileMode) error

func (*WrappedFS) OpenWriter added in v0.1.3

func (w *WrappedFS) OpenWriter(name string, flag int) (io.WriteCloser, error)

func (*WrappedFS) ReadDir added in v0.1.3

func (w *WrappedFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*WrappedFS) ReadOnly added in v0.1.3

func (w *WrappedFS) ReadOnly() *WrappedFS

func (*WrappedFS) Remove added in v0.1.3

func (w *WrappedFS) Remove(name string) error

func (*WrappedFS) Rename added in v0.1.3

func (w *WrappedFS) Rename(name, newName string) error

func (*WrappedFS) Stat added in v0.1.3

func (w *WrappedFS) Stat(name string) (fs.FileInfo, error)

func (*WrappedFS) Truncate added in v0.1.3

func (w *WrappedFS) Truncate(name string, size int64) error

Jump to

Keyboard shortcuts

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