Documentation
¶
Overview ¶
Package camutil copies some unexported utilities from camlistore.org/cmd/cam{get,put}
Index ¶
- Variables
- func Base64ToRef(arg string) (br blob.Ref, err error)
- func Close() error
- func CopyFile(src, dst string) error
- func LinkOrCopy(src, dst string) error
- func MIMETypeFromReader(r io.Reader) (mime string, reader io.Reader)
- func MatchMime(_ string, data []byte) string
- func NewClient(server string, clientOpts ...Option) (*client.Client, error)
- func ParseBlobNames(items []blob.Ref, names []string) ([]blob.Ref, error)
- func RefToBase64(br blob.Ref) string
- func SetLogger(lgr *slog.Logger)
- func SetupBasicAuthChecker(handler http.HandlerFunc, camliAuth string) http.HandlerFunc
- type BadgerCache
- type Downloader
- type MimeCache
- type Option
- type Uploader
- func (u *Uploader) Close() error
- func (u *Uploader) FromReader(ctx context.Context, fileName string, r io.Reader) (blob.Ref, error)
- func (u *Uploader) FromReaderInfo(ctx context.Context, fi os.FileInfo, mime string, r io.Reader) (blob.Ref, error)
- func (u *Uploader) NewPermanode(ctx context.Context, attrs map[string]string) (blob.Ref, error)
- func (u *Uploader) SetPermanodeAttrs(ctx context.Context, perma blob.Ref, attrs map[string]string) error
- func (u *Uploader) UploadBytes(ctx context.Context, r io.Reader) (blob.Ref, error)
- func (u *Uploader) UploadFile(ctx context.Context, path, mime string, permanode bool) (content, perma blob.Ref, err error)
- func (u *Uploader) UploadFileExt(ctx context.Context, path string, permanode bool) (content, perma blob.Ref, err error)
- func (u *Uploader) UploadFileExtLazyAttr(ctx context.Context, path string, attrs map[string]string) (content, perma blob.Ref, err error)
- func (u *Uploader) UploadFileLazyAttr(ctx context.Context, path, mime string, attrs map[string]string) (content, perma blob.Ref, err error)
- func (u *Uploader) UploadFileMIME(ctx context.Context, fileName, mimeType string) (content blob.Ref, err error)
- func (u *Uploader) UploadReaderInfoLazyAttr(ctx context.Context, fi os.FileInfo, mime string, r io.Reader, ...) (content, perma blob.Ref, err error)
Constants ¶
This section is empty.
Variables ¶
var DefaultMaxMemMimeCacheSize = 1024
DefaultMaxMemMimeCacheSize is the maximum size of in-memory mime cache
var (
ErrEmptyResponse = errors.New("empty resonse")
)
var ErrFileIsEmpty = errors.New("file is empty")
ErrFileIsEmpty is the error for zero length files
var ErrNotSupported = errors.New("operation not supported")
var InsecureTLS bool
InsecureTLS sets client's InsecureTLS
var SkipIrregular bool
SkipIrregular makes camget skip not regular files.
Functions ¶
func Base64ToRef ¶
Base64ToRef decodes a base64-encoded blobref
func CopyFile ¶
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 ¶
LinkOrCopy links src to dst if possible; copies if not
func MIMETypeFromReader ¶
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 NewClient ¶
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 ¶
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 ¶
RefToBase64 returns a base64-encoded version of the ref
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 ¶
Downloader is the struct for downloading file/dir blobs
func NewDownloader ¶
func NewDownloader(server string, options ...Option) (*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)
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 ¶
NewMimeCache creates a new mime cache - in-memory + on-disk (persistent)
type Option ¶ added in v0.15.1
type Option func(*clientOptions)
func WithCapCtime ¶ added in v0.15.2
func WithNoCache ¶ added in v0.15.2
func WithRetryTransport ¶ added in v0.15.1
func WithSkipHaveCache ¶ added in v0.15.2
type Uploader ¶
type Uploader struct { *client.Client blobserver.StatReceiver *schema.Signer // contains filtered or unexported fields }
Uploader holds the server and args
func NewUploader ¶
NewUploader returns a new uploader for uploading files to the given server
func (*Uploader) FromReader ¶
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 ¶
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
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.