fsd

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 35 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DefaultTCPPort = 12358
	DefaultWSPort  = 80
)

The default ports that fsd listens on.

Variables

View Source
var ErrNilConfiguration = errors.New("illegal nil configuration data")

ErrNilConfiguration is returned when a ClientConfig fails to validate.

Functions

func AreEqual added in v0.1.13

func AreEqual(c *ClientConfig, d *ClientConfig) bool

AreEqual returns true iff the two configurations are equal.

Types

type Client

type Client struct {
	log.BasicLogable
	io.Closer
	// contains filtered or unexported fields
}

Client is the client-view of the server.

func NewClient

func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error)

NewClient returns a new client view of the server specified by the configuration cfg.

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, dst string, src string) (int64, error)

Copy copies the contents of the file at src to dst. If src does not exist or is not a file, then fs/errors.NotExist is returned. If dst's parent directory does not exist, an fs/errors.NotExist error is returned; if the parent exists but is not a directory then an fs/errors.NotDirectory error is returned; an fs/errors.Exist error is returned if a file or directory with path dst already exists. Returns the number of bytes copied.

func (*Client) CopyAll

func (c *Client) CopyAll(ctx context.Context, dst string, src string) error

CopyAll recursively copies the file or directory structure rooted at path src to path dst. If src does not exist, then fs/errors.NotExist is returned. If dst's parent directory does not exist, an fs/errors.NotExist error is returned; an fs/errors.Exist error is returned if a file or directory with path dst already exists.

func (*Client) CopyTo

func (c *Client) CopyTo(ctx context.Context, p string, r io.Reader) (n int64, err error)

CopyTo copies the contents of r to p. If p's parent directory does not exist, an fs/errors.NotExist error is returned; if the parent exists but is not a directory then an fs/errors.NotDirectory error is returned; an fs/errors.Exist error is returned if a file or directory with path p already exists. Returns the number of bytes copied.

func (*Client) Dir

func (c *Client) Dir(ctx context.Context, p string) (fs.DirIterator, error)

Dir returns an iterator containing metadata for the files and directories within the directory with path p. If the path p does not exist then an fs/errors.NotExist error is returned; if the path p exists but is not a directory then an fs/errors.NotDirectory error will be returned. It is the caller's responsibility to call Close on the returned fs.DirIterator, otherwise resources may leak.

func (*Client) Download

func (c *Client) Download(ctx context.Context, p string) (fs.Reader, error)

Download returns an fs.Reader reading from contents of the file with the path p. If no file with path p exists, an fs/errors.NotFile is returned. It is the caller's responsibility to call Close on the returned fs.Reader, otherwise resources may leak.

func (*Client) DownloadMetadata

func (c *Client) DownloadMetadata(ctx context.Context, p string) (*fs.Metadata, error)

DownloadMetadata returns the metadata for the file or directory with the path p. If a file or directory with this path does not exist, an fs/errors.NotExist error is returned.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, p string) (bool, error)

Exists returns true if and only if path p exists.

func (*Client) Hash

func (c *Client) Hash(ctx context.Context, p string, h crypto.Hash) ([]byte, error)

Hash returns the hash of the file with path p, using the hash h. If the hash is not available (as determined by crypto.Hash.Available) then an fs/errors.HashNotAvailable error will be returned. If the path does not exist, or is a directory, an fs/errors.NotExist error is returned.

func (*Client) IsDir

func (c *Client) IsDir(ctx context.Context, p string) (bool, error)

IsDir returns true if and only if path p exists and is a directory.

func (*Client) IsDirEmpty

func (c *Client) IsDirEmpty(ctx context.Context, p string) (bool, error)

IsDirEmpty returns true if and only if path p exists and is an empty directory.

func (*Client) IsFile

func (c *Client) IsFile(ctx context.Context, p string) (bool, error)

IsFile returns true if and only if path p exists and is a file.

func (*Client) Mkdir

func (c *Client) Mkdir(ctx context.Context, p string) error

Mkdir creates the directory with the path p. If p's parent directory does not exist, an fs/errors.NotExist error is returned; if the parent exists but is not a directory then an fs/errors.NotDirectory error is returned; if a file or directory with that path already exists then an fs/errors.Exist error is returned.

func (*Client) MkdirRecursive

func (c *Client) MkdirRecursive(ctx context.Context, p string) error

MkdirRecursive creates the directory with the given path p, along with any intermediate directories as necessary. An fs/errors.Exist error is returned if a file or directory with that path already exists, or if a file already exists with an intermediate path.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, p string) error

Remove attempts to remove the file or directory with the path p. If the path does not exist, an fs/errors.NotExist error is returned. If the path is a directory and is non-empty or is "/", an fs/errors.DirNotEmpty error is returned.

func (*Client) RemoveAll

func (c *Client) RemoveAll(ctx context.Context, p string) error

RemoveAll removes path p if p is a file, and removes p and all its contents if p is a directory. If the path does not exist, RemoveAll returns nil (no error).

func (*Client) RemoveFile

func (c *Client) RemoveFile(ctx context.Context, p string) error

RemoveFile attempts to delete the file with path p. If p is not a file then the error fs/errors.NotFile will be returned.

func (*Client) Rmdir

func (c *Client) Rmdir(ctx context.Context, p string) error

Rmdir removes the path p if p is an empty directory. If the path is not a directory, returns fs/errors.NotDirectory; if the directory is not empty or is "/", returns fs/errors.DirNotEmpty.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, p string) (fs.Writer, error)

Upload returns an fs.Writer, writing to the path p. If p's parent directory does not exist, an fs/errors.NotExist error is returned; if the parent exists but is not a directory then an fs/errors.NotDirectory error is returned; if a file or directory with path p already exists then an fs/errors.Exist error is returned. It is the caller's responsibility to call Close on the returned fs.Writer, otherwise resources may leak.

type ClientConfig

type ClientConfig struct {
	Address     *address.Address // The address to connect to
	SSLDisabled bool             // Disable SSL?
	SSLCert     []byte           // The SSL certificate (if any)
}

ClientConfig describes the configuration options we allow a user to set on a client connection.

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns a new client configuration initialised with the default values.

The initial default value for the host will be read from the environment variable

PCAS_FS_ADDRESS = "hostname[:port]" or "ws://host/path"

on package init.

func SetDefaultConfig

func SetDefaultConfig(c *ClientConfig) *ClientConfig

SetDefaultConfig sets the default client configuration to c and returns the old default configuration. This change will be reflected in future calls to DefaultConfig.

func (*ClientConfig) Copy

func (c *ClientConfig) Copy() *ClientConfig

Copy returns a copy of the configuration.

func (*ClientConfig) Hash added in v0.1.13

func (c *ClientConfig) Hash() uint32

Hash returns a hash for the configuration.

func (*ClientConfig) URI

func (c *ClientConfig) URI() string

URI returns the URI connection string.

Note that the returned string may differ slightly from the value returned c.Address.URI(). For example, if c.Address omits a port number, an appropriate default port number is used here.

func (*ClientConfig) Validate

func (c *ClientConfig) Validate() error

Validate validates the client configuration, returning an error if there's a problem.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option sets options on a kvdb server.

func Fs

func Fs(S fs.Interface) Option

Fs sets the underlying filesystem to use

func SSLCertAndKey

func SSLCertAndKey(crt []byte, key []byte) Option

SSLCertAndKey adds the given SSL public certificate and private key to the server.

type Server

Server handles client communication.

func NewServer

func NewServer(options ...Option) (*Server, error)

NewServer returns a new fsd server.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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