Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) Copy(src FileID, dst string) (FileID, error)
- func (c *Client) CopyWithContext(ctx context.Context, src FileID, dst string) (FileID, error)
- func (c *Client) Delete(file FileID) error
- func (c *Client) DeleteWithContext(ctx context.Context, file FileID) error
- func (c *Client) Download(file FileID, w io.Writer) error
- func (c *Client) DownloadWithContext(ctx context.Context, file FileID, w io.Writer) error
- func (c *Client) Head(name string, opts *HeadOpts) FileIterator
- func (c *Client) HeadWithContext(ctx context.Context, name string, opts *HeadOpts) FileIterator
- func (c *Client) List(prefix string, opts *ListOpts) FileIterator
- func (c *Client) ListWithContext(ctx context.Context, prefix string, opts *ListOpts) FileIterator
- func (c *Client) Upload(r io.Reader, dst string) (FileID, error)
- func (c *Client) UploadWithContext(ctx context.Context, r io.Reader, dst string, mode CompressMode) (FileID, error)
- type CompressMode
- type FileID
- type FileInfo
- type FileIterator
- type HeadOpts
- type ListOpts
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a file with a given ID cannot be found on the remote.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements methods to interact with a JotFS server.
func New ¶
New returns a new Client connecting to a JotFS server at the given endpoint URL. Optional configuration may be set with opts.
Example ¶
package main
import (
"net/http"
"github.com/jotfs/jot"
)
func main() {
jot.New("http://example.com:6777", http.DefaultClient, nil)
}
Output:
Example (Options) ¶
package main
import (
"net/http"
"github.com/jotfs/jot"
)
func main() {
jot.New("https://jotfs.example.com", http.DefaultClient, &jot.Options{
Compression: jot.CompressNone,
})
}
Output:
func (*Client) Copy ¶
Copy makes a copy of a file from src to dst and returns the ID of the new file. Returns jotfs.ErrNotFound if the src does not exist.
func (*Client) CopyWithContext ¶
CopyWithContext is the same as Copy with a user supplied context.
func (*Client) Delete ¶
Delete deletes a file with a given ID. Returns jotfs.ErrNotFound if the file does not exist.
func (*Client) DeleteWithContext ¶
DeleteWithContext is the same as Delete with a user supplied context.
func (*Client) Download ¶
Download retrieves a file and writes it to w. Returns jotfs.ErrNotFound if the file does not exist.
Example ¶
package main
import (
"bytes"
"log"
"net/http"
"strings"
"github.com/jotfs/jot"
)
func main() {
client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
if err != nil {
log.Fatal(err)
}
r := strings.NewReader("Hello World!")
fileID, err := client.Upload(r, "/notes/today.txt")
if err != nil {
log.Fatal(err)
}
var w bytes.Buffer
err = client.Download(fileID, &w)
if err != nil {
log.Fatal(err)
}
}
Output:
func (*Client) DownloadWithContext ¶
DownloadWithContext is the same as Download with a user supplied context.
func (*Client) Head ¶
func (c *Client) Head(name string, opts *HeadOpts) FileIterator
Head returns an iterator over the versions of a file with a given name.
func (*Client) HeadWithContext ¶
HeadWithContext is the same as Head with a user supplied context.
func (*Client) List ¶
func (c *Client) List(prefix string, opts *ListOpts) FileIterator
List returns an iterator over all versions of all files with a name matching the given prefix. Files may be excluded / included by supplying a ListOpts struct.
func (*Client) ListWithContext ¶
ListWithContext is the same as List with a user supplied context.
func (*Client) Upload ¶
Upload reads data from r and uploads it to the server, creating a new file version at dst. If a file already exists at the destination it will be kept if either:
- File versioning is currently enabled on the server
- File versioning was enabled when the existing version was uploaded
Otherwise the latest version will be overwritten.
Example ¶
package main
import (
"fmt"
"log"
"net/http"
"strings"
"github.com/jotfs/jot"
)
func main() {
client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
if err != nil {
log.Fatal(err)
}
r := strings.NewReader("Hello World!")
fileID, err := client.Upload(r, "/notes/today.txt")
if err != nil {
log.Fatal(err)
}
fmt.Printf("fileID = %x\n", fileID.Marshal())
}
Output:
type CompressMode ¶
type CompressMode uint8
CompressMode represents the algorithm used to compress data.
const ( // Zstandard compression CompressZstd CompressMode = 0 // No compression CompressNone CompressMode = 1 )
Data compression modes
type FileID ¶
type FileID [sumSize]byte
FileID represents a unique ID for a file on a JotFS server.
func UnmarshalFileID ¶
UnmarshalFileID converts a byte slice to a FileID.
type FileIterator ¶
type FileIterator interface {
// Next returns the next FileInfo from the iterator. It returns io.EOF when the end
// of the iterator is reached. The FileInfo is always invalid if the error is not nil.
Next() (FileInfo, error)
}
FileIterator is an iterator over a stream of FileInfo returned by the methods List and Head.
type HeadOpts ¶
type HeadOpts struct {
// Limit is the maximum number of values to return from the iterator. Unlimited if
// unspecified.
Limit uint64
// BatchSize is the maximum number of values to retrieve at a time from the remote.
// Defaults to 1000.
BatchSize uint64
// Ascending, if set to true, returns values from the iterator in chronological
// order. False by default, in which case values are returned in reverse-chronological
// order
Ascending bool
}
HeadOpts specify the options for the method Head.
type ListOpts ¶
type ListOpts struct {
// Exclude will exclude any files matching the glob pattern.
Exclude string
// Include forces inclusion of any files matched by the Exclude pattern. It is
// ignored if Exclude is not provided.
Include string
// Limit is the maximum number of values to return from the iterator. Unlimited if
// unspecified.
Limit uint64
// BatchSize is the maximum number of values to retrieve at a time from the remote.
// Defaults to 1000.
BatchSize uint64
// Ascending, if set to true, returns values from the iterator in chronological
// order. False by default, in which case values are returned in reverse-chronological
// order
Ascending bool
}
ListOpts specify the options for the method List.
type Options ¶
type Options struct {
// Compression, if set, overrides the default compression mode, CompressZstd.
Compression CompressMode
// CacheDir specifies the directory the client may cache temporary data files.
// os.TempDir() by default. The directory must already exist.
CacheDir string
}
Options specifies optional configuration for a Client.