Documentation
¶
Overview ¶
Package dav is the explorer's WebDAV client: what browsing, downloading and uploading a share's files need of RFC 4918, and nothing else -- no locks, no properties beyond the four a listing shows.
It talks through any HTTP client (Doer): in a browser, the portal's (go-fileshare/portal/client), which adds the portal's header and keeps the token fresh; in a test, a plain one.
Index ¶
- func Exists(err error) bool
- func Fingerprint(name string, size, modified int64) string
- func Resumable(err error) bool
- type Client
- func (c *Client) Copy(ctx context.Context, from, to string) error
- func (c *Client) Delete(ctx context.Context, p string) error
- func (c *Client) DownloadURL(p string) string
- func (c *Client) Get(ctx context.Context, p string) (io.ReadCloser, error)
- func (c *Client) List(ctx context.Context, dir string) ([]Entry, error)
- func (c *Client) Mkdir(ctx context.Context, p string) error
- func (c *Client) Move(ctx context.Context, from, to string) error
- func (c *Client) Stat(ctx context.Context, p string) (Entry, error)
- func (c *Client) Upload(ctx context.Context, p string, src Source, overwrite bool, ...) (err error)
- type Doer
- type Entry
- type Error
- type Fingerprinter
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exists ¶
Exists says whether err is a MOVE or COPY refused because something is at the destination already (412 with Overwrite: F, RFC 4918 §10.6).
func Fingerprint ¶ added in v0.3.0
Fingerprint is the fingerprint of a file of that name, size and modification time (in any unit, consistently): 16 hex digits.
Types ¶
type Client ¶
type Client struct {
// Piece is the size of one upload piece. Default 8 MiB: the portal
// takes 16 MiB at most per PUT, and a smaller piece is a finer progress
// bar and a smaller retry.
Piece int64
// contains filtered or unexported fields
}
Client is the WebDAV of one server, rooted at base -- the portal's /dav/<server>, or a server's own URL.
func (*Client) DownloadURL ¶
DownloadURL is where a browser fetches p: a navigation, which the portal answers as an attachment.
func (*Client) Get ¶ added in v0.2.0
Get is the file p, to be read as it arrives and closed. A collection is not a file: p must not end in /.
func (*Client) List ¶
List is what the collection dir holds (PROPFIND, Depth 1), collections first, then by name; dir itself is not in it.
func (*Client) Move ¶
Move renames from to to; Copy copies it there, on the server. Neither replaces what is there already: Overwrite is F (RFC 4918 §10.6 makes T the default, which would silently destroy a file a rename landed on), and an existing destination is an error Exists recognises. A 207 is a move or copy that failed in part, and is an error too.
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, p string, src Source, overwrite bool, progress func(sent int64)) (err error)
Upload writes src at p, in pieces: each piece appended to a part file where the last ended (go-filesystems/webdav v0.6.0), then a MOVE to p -- so nobody sees half a file under its name, and no request holds the whole file. progress, when not nil, is told the bytes sent so far.
A Source that is a Fingerprinter resumes: its part file is named after its fingerprint (<p>.<fingerprint>.part), and an upload of the same file after a failure starts where the part ends -- once the part's last 64 KiB have been read back and found equal to the file's. A failure of the network or the server keeps the part for that; a refusal removes it. Any other Source starts from nothing (<p>.part), and a failure removes its part. A failure leaves p as it was.
type Entry ¶
type Entry struct {
Name string
Path string // from the root of the server's WebDAV, with a leading /; a collection's ends in /
Dir bool
Size int64
Modified time.Time
}
An Entry is one resource of a listing.
type Fingerprinter ¶ added in v0.3.0
type Fingerprinter interface {
Fingerprint() string
}
A Fingerprinter is a Source that can say which file it is -- its name, size and modification time, hashed -- so that an upload that failed can be resumed by the same file, and never by another one of the same name.