sys

package
v1.17.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 6 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
)

Functions

func SetAuthCommon added in v1.17.0

func SetAuthCommon(auth AuthorizeFunc)

func SetAuthorize added in v1.17.0

func SetAuthorize(auth AuthorizeFunc)

SetAuthorize sets the authorize callback function

Types

type AuthorizeFunc added in v1.10.0

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

type DiskFS

type DiskFS struct {
}

DiskFS implement file system on disk

func (*DiskFS) CreateDirectory added in v1.17.0

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

func (*DiskFS) GetFileHandler added in v1.17.0

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

func (*DiskFS) LoadProgress added in v1.14.0

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 added in v1.17.0

func (dfs *DiskFS) RemoveAllDirectories()

func (*DiskFS) RemoveProgress added in v1.14.0

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

func (*DiskFS) SaveProgress added in v1.14.0

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

func (*DiskFS) Stat added in v1.8.8

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) 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

	// 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 added in v1.8.17

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 added in v1.8.17

func (f *MemChanFile) Close() error

Close closes the buffer channel

func (*MemChanFile) Read added in v1.8.17

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 added in v1.8.17

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

Seek not implemented

func (*MemChanFile) Stat added in v1.8.17

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

Stat returns the file information

func (*MemChanFile) Sync added in v1.8.17

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 added in v1.8.17

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 added in v1.13.0

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 added in v1.13.0

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

WriteAt writes data to the file at a specific offset

type MemFileChanInfo added in v1.8.17

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

MemFileChanInfo represents file information

func (*MemFileChanInfo) Info added in v1.8.17

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

Info returns the file information

func (*MemFileChanInfo) IsDir added in v1.8.17

func (i *MemFileChanInfo) IsDir() bool

IsDir returns true if the file is a directory

func (*MemFileChanInfo) ModTime added in v1.8.17

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

ModTime returns the modification time of the file

func (*MemFileChanInfo) Mode added in v1.8.17

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

Mode returns the file mode bits

func (*MemFileChanInfo) Name added in v1.8.17

func (i *MemFileChanInfo) Name() string

Name returns the base name of the file

func (*MemFileChanInfo) Size added in v1.8.17

func (i *MemFileChanInfo) Size() int64

Size not implemented

func (*MemFileChanInfo) Sys added in v1.8.17

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

Sys returns the underlying data source (can return nil)

func (*MemFileChanInfo) Type added in v1.8.17

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 SignFunc

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

SignFunc sign method for request verification

type VerifyFunc added in v1.8.7

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

type VerifyWithFunc added in v1.8.14

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