fslib

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: CC0-1.0, CC0-1.0, CC0-1.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, f func() *rt.Table)

Register registers the given function that returns a table to be added to the package table using the given name (typically a name of a file store). If a function is already registered with the given name then it will be replaced; if the name coincides with one of the package functions or values then it will be overwritten. Note that any function registered after the package is loaded into the Lua runtime will not appear in that instance of the package.

func WrapConnectFunc

func WrapConnectFunc(fileStoreName string, g func(*rt.Thread, *rt.GoCont) (string, ConnectFunc, error)) func(*rt.Thread, *rt.GoCont) (rt.Cont, error)

WrapConnectFunc wraps the given function, converting it into a full connection function for Lua.

Types

type ConnectFunc

type ConnectFunc func(context.Context) (fs.Interface, error)

ConnectFunc defines a function that will connect to a file store.

type Fs

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

Fs wraps an fs.Interface.

func FsArg

func FsArg(c *rt.GoCont, n int) (*Fs, error)

FsArg turns a continuation argument into an *Fs.

func ValueToFs

func ValueToFs(v rt.Value) (*Fs, bool)

ValueToFs turns a lua value to an *Fs, if possible.

func (*Fs) Chdir

func (c *Fs) Chdir(ctx context.Context, p string) error

Chdir sets the current working directory.

func (*Fs) Close

func (c *Fs) Close() error

Close prevents any further queries through this connection.

func (*Fs) Copy

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

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

func (*Fs) CopyAll

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

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

func (*Fs) Dir

func (c *Fs) Dir(ctx context.Context, p string) (itr fs.DirIterator, err 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 errors.NotExist error is returned; if the path p exists but is not a directory then an errors.NotDirectory error will be returned.

func (*Fs) Download

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

Download returns the contents of the file with the path p. It is the caller's responsibility to call Close on the returned io.ReadCloser, otherwise resources may leak.

func (*Fs) DownloadMetadata

func (c *Fs) DownloadMetadata(ctx context.Context, p string) (md *fs.Metadata, err 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 errors.NotExist error is returned.

func (*Fs) Exists

func (c *Fs) Exists(ctx context.Context, p string) (ok bool, err error)

Exists returns true if and only if path p exists in s.

func (*Fs) GetTimeout

func (c *Fs) GetTimeout() time.Duration

GetTimeout returns the timeout.

func (*Fs) Getwd

func (c *Fs) Getwd() (string, error)

Getwd returns the current working directory.

func (*Fs) Hash

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

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

func (*Fs) IsClosed

func (c *Fs) IsClosed() bool

IsClosed returns true iff the connection is closed.

func (*Fs) IsDir

func (c *Fs) IsDir(ctx context.Context, p string) (ok bool, err error)

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

func (*Fs) IsDirEmpty

func (c *Fs) IsDirEmpty(ctx context.Context, p string) (ok bool, err error)

IsDirEmpty returns true if and only if path p exists in s and is an empty directory. If the path is not a directory, returns errors.NotDirectory.

func (*Fs) IsFile

func (c *Fs) IsFile(ctx context.Context, p string) (ok bool, err error)

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

func (*Fs) Mkdir

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

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

func (*Fs) MkdirRecursive

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

MkdirRecursive creates the directory with the given path p, along with any intermediate directories as necessary. An 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 (*Fs) Remove

func (c *Fs) 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 errors.NotExist error is returned. If the path is a directory and is non-empty or is "/", an errors.DirNotEmpty error is returned.

func (*Fs) RemoveAll

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

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

func (*Fs) RemoveFile

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

RemoveFile attempts to delete the file with path p in s. If p is not a file, then the error ErrNotFile will be returned.

func (*Fs) ReplaceFile

func (c *Fs) ReplaceFile(ctx context.Context, p string) (w fs.Writer, err error)

ReplaceFile attempts to create or replace the file with path p in s. If p's parent directory does not exist, an errors.NotExist error is returned; if the parent exists but is not a directory then an errors.NotDirectory error is returned; if p exists but is not a file, then the error errors.NotFile will be returned. It is the caller's responsibility to call Close on the returned Writer, otherwise resources may leak.

func (*Fs) Rmdir

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

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

func (*Fs) SetTimeout

func (c *Fs) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout. A negative timeout is interpreted to mean no timeout.

func (*Fs) String

func (c *Fs) String() string

String returns a string description of the connection.

func (*Fs) Upload

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

Upload returns a Writer writing to the path p. If p's parent directory does not exist, an errors.NotExist error is returned; if the parent exists but is not a directory then an errors.NotDirectory error is returned; if a file or directory with path p already exists then an errors.Exist error is returned.

type Reader

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

Reader wraps an fs.Reader with a rolling timeout.

func ReaderArg

func ReaderArg(c *rt.GoCont, n int) (*Reader, error)

ReaderArg turns a continuation argument into a *Reader.

func ValueToReader

func ValueToReader(v rt.Value) (*Reader, bool)

ValueToReader turns a Lua value to a *Reader if possible.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the reader.

func (*Reader) GetTimeout

func (r *Reader) GetTimeout() time.Duration

GetTimeout returns the current timeout duration.

func (*Reader) IsClosed

func (r *Reader) IsClosed() bool

IsClosed returns true iff the file is known to be closed.

func (*Reader) Name

func (r *Reader) Name() string

Name returns the name of the file as presented to Download.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read reads up to len(p) bytes into p. It returns the number of bytes read and any error encountered.

func (*Reader) SetTimeout

func (r *Reader) SetTimeout(d time.Duration)

SetTimeout sets the timeout duration.

func (*Reader) String

func (r *Reader) String() string

String returns a string description of the reader.

type Writer

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

Writer wraps an fs.Writer with a rolling timeout.

func ValueToWriter

func ValueToWriter(v rt.Value) (*Writer, bool)

ValueToWriter turns a Lua value to a *Writer if possible.

func WriterArg

func WriterArg(c *rt.GoCont, n int) (*Writer, error)

WriterArg turns a continuation argument into a *Writer.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer.

func (*Writer) GetTimeout

func (w *Writer) GetTimeout() time.Duration

GetTimeout returns the current timeout duration.

func (*Writer) IsClosed

func (w *Writer) IsClosed() bool

IsClosed returns true iff the file is known to be closed.

func (*Writer) Name

func (w *Writer) Name() string

Name returns the name of the file as presented to Upload.

func (*Writer) SetTimeout

func (w *Writer) SetTimeout(d time.Duration)

SetTimeout sets the timeout duration.

func (*Writer) String

func (w *Writer) String() string

String returns a string description of the writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p and any error encountered that caused the write to stop early.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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