sys

package
v0.0.0-...-1da9c7e Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Provides functions and data structures for working with memory and disk file systems.

Package sys provides platform-independent interfaces to support webassembly runtime

Index

Constants

This section is empty.

Variables

View Source
var (
	//Files file system implementation on sdk. DiskFS doesn't work on webassembly. it should be initialized with common.NewMemFS()
	Files FS = NewDiskFS()

	//Sleep  pauses the current goroutine for at least the duration.
	//  time.Sleep will stop webassembly main thread. it should be bridged to javascript method on webassembly sdk
	Sleep = time.Sleep

	// Sign sign method. it should be initialized on different platform.
	Sign         SignFunc
	SignWithAuth SignFunc

	// Verify verify method. it should be initialized on different platform.
	Verify VerifyFunc

	// Verify verify method. it should be initialized on different platform.
	VerifyWith VerifyWithFunc

	Authorize AuthorizeFunc

	AuthCommon AuthorizeFunc

	VerifyEd25519With VerifyWithFunc
)

Functions

func SetAuthCommon

func SetAuthCommon(auth AuthorizeFunc)

func SetAuthorize

func SetAuthorize(auth AuthorizeFunc)

SetAuthorize sets the authorize callback function

Types

type AuthorizeFunc

type AuthorizeFunc func(msg string) (string, error)

type DiskFS

type DiskFS struct {
}

DiskFS implement file system on disk

func (*DiskFS) CreateDirectory

func (dfs *DiskFS) CreateDirectory(_ string) error

func (*DiskFS) GetFileHandler

func (dfs *DiskFS) GetFileHandler(_, name string) (File, error)

func (*DiskFS) LoadProgress

func (dfs *DiskFS) LoadProgress(progressID string) ([]byte, error)

func (*DiskFS) MkdirAll

func (dfs *DiskFS) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path

func (*DiskFS) Open

func (dfs *DiskFS) Open(name string) (File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func (*DiskFS) OpenFile

func (dfs *DiskFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*DiskFS) ReadFile

func (dfs *DiskFS) ReadFile(name string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents.

func (*DiskFS) Remove

func (dfs *DiskFS) Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func (*DiskFS) RemoveAllDirectories

func (dfs *DiskFS) RemoveAllDirectories()

func (*DiskFS) RemoveProgress

func (dfs *DiskFS) RemoveProgress(progressID string) error

func (*DiskFS) SaveProgress

func (dfs *DiskFS) SaveProgress(progressID string, data []byte, perm fs.FileMode) error

func (*DiskFS) Stat

func (dfs *DiskFS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

func (*DiskFS) StoreLogs

func (dfs *DiskFS) StoreLogs(key string, data string) error

func (*DiskFS) WriteFile

func (dfs *DiskFS) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to a file named by filename.

type FS

type FS interface {

	// Open opens the named file for reading. If successful, methods on
	// the returned file can be used for reading; the associated file
	// descriptor has mode O_RDONLY.
	// If there is an error, it will be of type *PathError.
	Open(name string) (File, error)

	// OpenFile open a file
	OpenFile(name string, flag int, perm os.FileMode) (File, error)

	// ReadFile reads the file named by filename and returns the contents.
	ReadFile(name string) ([]byte, error)

	// WriteFile writes data to a file named by filename.
	WriteFile(name string, data []byte, perm fs.FileMode) error

	Stat(name string) (fs.FileInfo, error)

	// Remove removes the named file or (empty) directory.
	// If there is an error, it will be of type *PathError.
	Remove(name string) error

	//MkdirAll creates a directory named path
	MkdirAll(path string, perm os.FileMode) error

	// LoadProgress load progress
	LoadProgress(progressID string) ([]byte, error)

	// SaveProgress save progress
	SaveProgress(progressID string, data []byte, perm fs.FileMode) error

	// RemoveProgress remove progress
	RemoveProgress(progressID string) error

	StoreLogs(key string, data string) error

	// Create Directory
	CreateDirectory(dirID string) error

	// GetFileHandler
	GetFileHandler(dirID, name string) (File, error)

	// Remove all created directories(used in download directory)
	RemoveAllDirectories()
}

FS An FS provides access to a hierarchical file system.

func NewDiskFS

func NewDiskFS() FS

NewDiskFS create DiskFS instance

type File

type File interface {
	Stat() (fs.FileInfo, error)
	Read([]byte) (int, error)
	Write(p []byte) (n int, err error)

	Sync() error
	Seek(offset int64, whence int) (ret int64, err error)

	Close() error
}

type KeyPair

type KeyPair struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

KeyPair private and publickey

type MemChanFile

type MemChanFile struct {
	Name           string
	Buffer         chan []byte // file content
	Mode           fs.FileMode // FileInfo.Mode
	ModTime        time.Time   // FileInfo.ModTime
	ChunkWriteSize int         //  0 value means no limit
	Sys            interface{} // FileInfo.Sys
	ErrChan        chan error
	// contains filtered or unexported fields
}

MemChanFile used to read or write file content sequentially through a buffer channel. Not aware of the file size, so it can't seek or truncate.

func (*MemChanFile) Close

func (f *MemChanFile) Close() error

Close closes the buffer channel

func (*MemChanFile) Read

func (f *MemChanFile) Read(p []byte) (int, error)

Read reads data from the file through the buffer channel It returns io.EOF when the buffer channel is closed.

  • p: file in bytes loaded from the buffer channel

func (*MemChanFile) Seek

func (f *MemChanFile) Seek(offset int64, whence int) (ret int64, err error)

Seek not implemented

func (*MemChanFile) Stat

func (f *MemChanFile) Stat() (fs.FileInfo, error)

Stat returns the file information

func (*MemChanFile) Sync

func (f *MemChanFile) Sync() error

Sync write the data chunk to the buffer channel It writes the data to the buffer channel in chunks of ChunkWriteSize. If ChunkWriteSize is 0, it writes the data as a whole.

func (*MemChanFile) Write

func (f *MemChanFile) Write(p []byte) (n int, err error)

Write writes data to the file through the buffer channel It writes the data to the buffer channel in chunks of ChunkWriteSize. If ChunkWriteSize is 0, it writes the data as a whole.

  • p: file in bytes to write to the buffer channel

type MemFile

type MemFile struct {
	Name    string
	Buffer  []byte      // file content
	Mode    fs.FileMode // FileInfo.Mode
	ModTime time.Time   // FileInfo.ModTime
	Sys     interface{} // FileInfo.Sys
	// contains filtered or unexported fields
}

MemFile represents a file totally loaded in memory Aware of the file size, so it can seek and truncate.

func (*MemFile) Close

func (f *MemFile) Close() error

func (*MemFile) InitBuffer

func (f *MemFile) InitBuffer(size int)

InitBuffer initializes the buffer with a specific size

func (*MemFile) Read

func (f *MemFile) Read(p []byte) (int, error)

Read reads data from the file

func (*MemFile) Seek

func (f *MemFile) Seek(offset int64, whence int) (ret int64, err error)

func (*MemFile) Stat

func (f *MemFile) Stat() (fs.FileInfo, error)

Stat returns the file information

func (*MemFile) Sync

func (f *MemFile) Sync() error

Sync not implemented

func (*MemFile) Write

func (f *MemFile) Write(p []byte) (n int, err error)

Write writes data to the file

func (*MemFile) WriteAt

func (f *MemFile) WriteAt(p []byte, offset int64) (n int, err error)

WriteAt writes data to the file at a specific offset

type MemFileChanInfo

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

MemFileChanInfo represents file information

func (*MemFileChanInfo) Info

func (i *MemFileChanInfo) Info() (fs.FileInfo, error)

Info returns the file information

func (*MemFileChanInfo) IsDir

func (i *MemFileChanInfo) IsDir() bool

IsDir returns true if the file is a directory

func (*MemFileChanInfo) ModTime

func (i *MemFileChanInfo) ModTime() time.Time

ModTime returns the modification time of the file

func (*MemFileChanInfo) Mode

func (i *MemFileChanInfo) Mode() fs.FileMode

Mode returns the file mode bits

func (*MemFileChanInfo) Name

func (i *MemFileChanInfo) Name() string

Name returns the base name of the file

func (*MemFileChanInfo) Size

func (i *MemFileChanInfo) Size() int64

Size not implemented

func (*MemFileChanInfo) Sys

func (i *MemFileChanInfo) Sys() interface{}

Sys returns the underlying data source (can return nil)

func (*MemFileChanInfo) Type

func (i *MemFileChanInfo) Type() fs.FileMode

Type returns the file mode type

type MemFileInfo

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

MemFileInfo represents file information

func (*MemFileInfo) Info

func (i *MemFileInfo) Info() (fs.FileInfo, error)

Info returns the file information

func (*MemFileInfo) IsDir

func (i *MemFileInfo) IsDir() bool

IsDir returns true if the file is a directory

func (*MemFileInfo) ModTime

func (i *MemFileInfo) ModTime() time.Time

ModTime returns the modification time of the file

func (*MemFileInfo) Mode

func (i *MemFileInfo) Mode() fs.FileMode

Mode returns the file mode bits

func (*MemFileInfo) Name

func (i *MemFileInfo) Name() string

Name returns the base name of the file

func (*MemFileInfo) Size

func (i *MemFileInfo) Size() int64

Size returns the size of the file

func (*MemFileInfo) Sys

func (i *MemFileInfo) Sys() interface{}

Sys returns the underlying data source (can return nil)

func (*MemFileInfo) Type

func (i *MemFileInfo) Type() fs.FileMode

Type returns the file mode type

type PipeFile

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

wrapper over io pipe to implement File interface

func NewPipeFile

func NewPipeFile() *PipeFile

func (*PipeFile) Close

func (pf *PipeFile) Close() error

func (*PipeFile) Read

func (pf *PipeFile) Read(p []byte) (int, error)

func (*PipeFile) Seek

func (pf *PipeFile) Seek(offset int64, whence int) (int64, error)

func (*PipeFile) Stat

func (pf *PipeFile) Stat() (fs.FileInfo, error)

func (*PipeFile) Sync

func (pf *PipeFile) Sync() error

func (*PipeFile) Write

func (pf *PipeFile) Write(p []byte) (int, error)

type SignFunc

type SignFunc func(hash string, signatureScheme string, keys []KeyPair) (string, error)

SignFunc sign method for request verification

type VerifyFunc

type VerifyFunc func(signature string, msg string) (bool, error)

type VerifyWithFunc

type VerifyWithFunc func(pk, signature string, msg string) (bool, error)

Jump to

Keyboard shortcuts

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