client

package
v0.0.0-...-a1758a3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package client provides the pcopy client that can be used to its server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a pcopy client. It can be used to communicate with the server to verify the user password, and ultimately to copy/paste files.

func NewClient

func NewClient(conf *config.Config, username, password string) (*Client, error)

NewClient creates a new pcopy client. It fails if the ServerAddr is not filled.

func (*Client) Copy

func (c *Client) Copy(reader io.ReadCloser, id string, ttl time.Duration, mode string, stream bool) (*server.File, error)

Copy streams the data from reader to the server via a HTTP PUT request. The id parameter is the file identifier that can be used to paste the data later using Paste.

func (*Client) CopyFiles

func (c *Client) CopyFiles(files []string, id string, ttl time.Duration, mode string, stream bool) (*server.File, error)

CopyFiles creates a ZIP archive of the given files and streams it to the server using the Copy method. No temporary ZIP archive is created on disk. It's all streamed.

func (*Client) FileInfo

func (c *Client) FileInfo(id string) (*server.File, error)

FileInfo retrieves file metadata for the given file

func (*Client) Paste

func (c *Client) Paste(writer io.Writer, id string) error

Paste reads the file with the given id from the server and writes it to writer.

func (*Client) PasteFiles

func (c *Client) PasteFiles(dir string, id string) error

PasteFiles reads the file with the given id from the server (assuming that it is a ZIP archive) and unpacks it to dir. This method creates a temporary file of the archive first before unpacking.

func (*Client) Reserve

func (c *Client) Reserve(id string) (*server.File, error)

Reserve requests a file name from the server and reserves it for a very short period of time. This is a workaround to be able to stream to a random file ID.

func (*Client) ServerInfo

func (c *Client) ServerInfo() (*server.Info, error)

ServerInfo queries the server for information (password salt, advertised address) required during the join operation. This method will first attempt to securely connect over HTTPS, and (if that fails) fall back to skipping certificate verification. In the latter case, it will download and return the server certificate so the client can pin them.

func (*Client) Verify

func (c *Client) Verify(cert *x509.Certificate, key *crypto.Key) error

Verify verifies that the given key (derived from the user password) is in fact correct by calling the server's verify endpoint. If the call fails, the key is assumed to be incorrect.

Jump to

Keyboard shortcuts

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