clipboard

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: 16 Imported by: 0

Documentation

Overview

Package clipboard provides the disk based clipboard implementation

Index

Constants

View Source
const (
	// FileRegexPart defines the regex for a valid file ID. Note that this does not include start/end markers,
	// as they can be different depending on the use case.
	FileRegexPart = `(?i)([a-z0-9][-_.a-z0-9]{1,100})`
)

Variables

View Source
var (
	// ErrBrokenPipe is returned when the target file is a pipe and the consumer prematurely interrupts reading
	ErrBrokenPipe = errors.New("broken pipe")

	// ErrInvalidFileID is returned in any method that deals with file ID input for reserved identifiers (ReadFile, WriteFile, ...)
	ErrInvalidFileID = errors.New("invalid file id")
)

Functions

This section is empty.

Types

type Clipboard

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

Clipboard is responsible for storing files on the file system. In addition to storage, it also takes care of expiring files, and of limiting total clipboard size and count.

func New

func New(config *config.Config) (*Clipboard, error)

New creates a new Clipboard using the given config

func (*Clipboard) Allow

func (c *Clipboard) Allow() bool

Allow increases the clipboard file counter and returns true if a new file may be added

func (*Clipboard) DeleteFile

func (c *Clipboard) DeleteFile(id string) error

DeleteFile removes the file with the given ID from the clipboard, including its metadata file

func (*Clipboard) Expire

func (c *Clipboard) Expire() error

Expire will use List to list all clipboard entries and delete the ones that have expired

func (*Clipboard) List

func (c *Clipboard) List() ([]*File, error)

List returns a metadata about the files in the clipboard

func (*Clipboard) MakePipe

func (c *Clipboard) MakePipe(id string) error

MakePipe creates a FIFO pipe that can be used for streaming

func (*Clipboard) ReadFile

func (c *Clipboard) ReadFile(id string, w io.Writer) error

ReadFile reads the file content from the clipboard and writes it to w

func (*Clipboard) Stat

func (c *Clipboard) Stat(id string) (*File, error)

Stat returns metadata about a file in a clipboard

func (*Clipboard) Stats

func (c *Clipboard) Stats() (*Stats, error)

Stats returns statistics about the current clipboard. It also updates the limiters with the current cumulative values.

func (*Clipboard) WriteFile

func (c *Clipboard) WriteFile(id string, meta *File, rc io.ReadCloser) error

WriteFile writes the entire content of rc to the clipboard entry as well as a metadata file. The method observes the per-file size limit as defined in the config, as well as the total clipboard size limit. If a limit is reached, it will return util.ErrLimitReached. When the target file is a FIFO pipe (see MakePipe) and the consumer prematurely interrupts reading, ErrBrokenPipe may be returned.

type File

type File struct {
	ID      string    `json:"-"`
	Size    int64     `json:"-"`
	ModTime time.Time `json:"-"`
	Pipe    bool      `json:"-"`
	Mode    string    `json:"mode"`
	Expires int64     `json:"expires"`
	Secret  string    `json:"secret"`
}

File defines the metadata file format stored next to each file

type Stats

type Stats struct {
	Count int
	Size  int64
}

Stats holds statistics about the current clipboard usage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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