camutil

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package camutil copies some unexported utilities from camlistore.org/cmd/cam{get,put}

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxMemMimeCacheSize = 1024

DefaultMaxMemMimeCacheSize is the maximum size of in-memory mime cache

View Source
var ErrFileIsEmpty = errors.New("file is empty")

ErrFileIsEmpty is the error for zero length files

View Source
var ErrNotSupported = errors.New("operation not supported")
View Source
var InsecureTLS bool

InsecureTLS sets client's InsecureTLS

View Source
var SkipIrregular bool

SkipIrregular makes camget skip not regular files.

Functions

func Base64ToRef

func Base64ToRef(arg string) (br blob.Ref, err error)

Base64ToRef decodes a base64-encoded blobref

func Close

func Close() error

Close closes the probably opened cached Uploaders and Downloaders

func CopyFile

func CopyFile(src, dst string) error

CopyFile is used by Windows (receive_windows.go) and when a posix filesystem doesn't support a link operation (e.g. Linux with an exfat external USB disk).

func LinkOrCopy

func LinkOrCopy(src, dst string) error

LinkOrCopy links src to dst if possible; copies if not

func MIMETypeFromReader

func MIMETypeFromReader(r io.Reader) (mime string, reader io.Reader)

MIMETypeFromReader takes a reader, sniffs the beginning of it, and returns the mime (if sniffed, else "") and a new reader that's the concatenation of the bytes sniffed and the remaining reader.

func MatchMime

func MatchMime(_ string, data []byte) string

MatchMime checks mime from the first 1024 bytes

func NewClient

func NewClient(server string) (*client.Client, error)

NewClient returns a new client for the given server. Auth is set up according to the client config (~/.config/camlistore/client-config.json) and the environment variables.

func ParseBlobNames

func ParseBlobNames(items []blob.Ref, names []string) ([]blob.Ref, error)

ParseBlobNames parses the blob names, appending to items, and returning the expanded slice, and error if happened. This uses blob.Parse, and can decode base64-encoded refs as a plus.

func RefToBase64

func RefToBase64(br blob.Ref) string

RefToBase64 returns a base64-encoded version of the ref

func SetLogger added in v0.12.0

func SetLogger(lgr *slog.Logger)

SetLogger sets the package-level *slog.Logger

func SetupBasicAuthChecker

func SetupBasicAuthChecker(handler http.HandlerFunc, camliAuth string) http.HandlerFunc

SetupBasicAuthChecker sets up a HTTP Basic authentication checker with the given camliAuth userpass:username:password[:+localhost,vivify=true] (see CAMLI_AUTH) string

Types

type BadgerCache added in v0.5.0

type BadgerCache struct {
	*cacher.CachingFetcher

	// Root is the temp directory being used to store files.
	// It is available mostly for debug printing.
	Root string
}

func NewBadgerCache added in v0.5.0

func NewBadgerCache(fetcher blob.Fetcher, maxSize int64) (*BadgerCache, error)

type Downloader

type Downloader struct {
	blob.Fetcher
	// contains filtered or unexported fields
}

Downloader is the struct for downloading file/dir blobs

func NewDownloader

func NewDownloader(server string, noCache bool) (*Downloader, error)

NewDownloader creates a new Downloader (client + properties + disk cache) for the server

func (*Downloader) Close

func (down *Downloader) Close()

Close closes the downloader (the underlying client)

func (*Downloader) Save

func (down *Downloader) Save(ctx context.Context, destDir string, contents bool, items ...blob.Ref) error

Save saves contents of the blobs into destDir as files

func (*Downloader) Start

func (down *Downloader) Start(ctx context.Context, contents bool, items ...blob.Ref) (io.ReadCloser, error)

Start starts the downloads of the blobrefs. Just the JSON schema if contents is false, else the content of the blob.

type MimeCache

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

MimeCache is the in-memory (LRU) and disk-based (kv) cache of mime types

func NewMimeCache

func NewMimeCache(filename string, maxMemCacheSize int) *MimeCache

NewMimeCache creates a new mime cache - in-memory + on-disk (persistent)

func (*MimeCache) Close

func (mc *MimeCache) Close() error

Close closes the probably open disk db (kv)

func (*MimeCache) Get

func (mc *MimeCache) Get(key string) string

Get returns the stored mimetype for the key - empty string if not found

func (*MimeCache) Set

func (mc *MimeCache) Set(key, mime string)

Set sets the mimetype for the key

type Uploader

type Uploader struct {
	*client.Client
	blobserver.StatReceiver
	*schema.Signer
	// contains filtered or unexported fields
}

Uploader holds the server and args

func NewUploader

func NewUploader(server string, capCtime bool, skipHaveCache bool) *Uploader

NewUploader returns a new uploader for uploading files to the given server

func (*Uploader) Close

func (u *Uploader) Close() error

Close closes the Client/Storage.

func (*Uploader) FromReader

func (u *Uploader) FromReader(ctx context.Context, fileName string, r io.Reader) (blob.Ref, error)

FromReader uploads the contents of the io.Reader.

func (*Uploader) FromReaderInfo

func (u *Uploader) FromReaderInfo(ctx context.Context, fi os.FileInfo, mime string, r io.Reader) (blob.Ref, error)

FromReaderInfo uploads the contents of r, wrapped with data from fi. Creation time (unixCtime) is capped at modification time (unixMtime), and a "mimeType" field is set, if mime is not empty.

func (*Uploader) NewPermanode

func (u *Uploader) NewPermanode(ctx context.Context, attrs map[string]string) (blob.Ref, error)

NewPermanode returns a new random permanode and sets the given attrs on it. Returns the permanode, and the error.

func (*Uploader) SetPermanodeAttrs

func (u *Uploader) SetPermanodeAttrs(ctx context.Context, perma blob.Ref, attrs map[string]string) error

SetPermanodeAttrs sets the attributes on the given permanode.

func (*Uploader) UploadBytes added in v0.4.0

func (u *Uploader) UploadBytes(ctx context.Context, r io.Reader) (blob.Ref, error)

UploadBytes uploads the contents of the io.Reader as "bytes" blob.

func (*Uploader) UploadFile

func (u *Uploader) UploadFile(
	ctx context.Context,
	path, mime string,
	permanode bool,
) (content, perma blob.Ref, err error)

UploadFile uploads the given path (file or directory, recursively), and returns the content ref, the permanode ref (if you asked for it), and error

func (*Uploader) UploadFileExt

func (u *Uploader) UploadFileExt(ctx context.Context, path string, permanode bool) (content, perma blob.Ref, err error)

UploadFileExt uploads the given path (file or directory, recursively), and returns the content ref, the permanode ref (if you asked for it), and error

func (*Uploader) UploadFileExtLazyAttr

func (u *Uploader) UploadFileExtLazyAttr(ctx context.Context, path string, attrs map[string]string) (content, perma blob.Ref, err error)

UploadFileExtLazyAttr uploads the given path (file or directory, recursively), and returns the content ref, the permanode ref (iff you added attributes).

func (*Uploader) UploadFileLazyAttr

func (u *Uploader) UploadFileLazyAttr(
	ctx context.Context,
	path, mime string,
	attrs map[string]string,
) (content, perma blob.Ref, err error)

UploadFileLazyAttr uploads the given path (file or directory, recursively), and returns the content ref, and the permanode ref iff attrs is not empty. It also sets the attributes on the permanode - but only those without "camli" prefix!

This is lazy, so it will NOT return an error if the permanode/attrs can't be created.

func (*Uploader) UploadFileMIME

func (u *Uploader) UploadFileMIME(ctx context.Context, fileName, mimeType string) (content blob.Ref, err error)

UploadFileMIME uploads a regular file with the given MIME type.

func (*Uploader) UploadReaderInfoLazyAttr

func (u *Uploader) UploadReaderInfoLazyAttr(
	ctx context.Context,
	fi os.FileInfo, mime string, r io.Reader,
	attrs map[string]string,
) (content, perma blob.Ref, err error)

UploadReaderLazyAttr uploads the contents of the reader as a file, returns the content ref, and the permanode ref iff attrs is not empty. It also sets the attributes on the permanode - but only those without "camli" prefix!

This is lazy, so it will NOT return an error if the permanode/attrs can't be created.

Jump to

Keyboard shortcuts

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