file

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package file provides goma file service implementation.

Index

Constants

View Source
const (
	// LargeFileThreshold defines a number of bytes to use FILE_META instead of FILE.
	LargeFileThreshold = 2 * 1024 * 1024

	// FileChunkSize defines a size of each FILE_CHUNK content.
	FileChunkSize = 2 * 1024 * 1024
)
View Source
const (
	// DefaultMaxMsgSize is max message size for file service.
	// file service will handle 2MB chunk * 5 chunks in a request.
	// grpc's default is 4MB.
	DefaultMaxMsgSize = 12 * 1024 * 1024
)

Variables

This section is empty.

Functions

func FromLocal

func FromLocal(ctx context.Context, fc filepb.FileServiceClient, fname string, blob *gomapb.FileBlob) (os.FileInfo, error)

FromLocal reads fname and fills in blob, and stores it in FileServiceClient.

func FromReader

func FromReader(ctx context.Context, fc filepb.FileServiceClient, r io.Reader, blob *gomapb.FileBlob) error

FromReader reads contents from r and fills in blob, and stores it in FileServiceClient if fc != nil. content size must be blob's FileSize.

func IsValid

func IsValid(blob *gomapb.FileBlob) bool

IsValid checks blob is valid FileBlob.

func Key

func Key(blob *gomapb.FileBlob) (string, error)

Key returns hash key for blob.

func ToLocal

func ToLocal(ctx context.Context, fc filepb.FileServiceClient, blob *gomapb.FileBlob, fname string) error

ToLocal writes FileBlob contents in fname. If FileBlob is FILE_META, it will fetch FILE_CHUNK using FileServiceClient.

Types

type BlobSpec

type BlobSpec struct {
	HashKey      string
	Blob         *gomapb.FileBlob
	IsExecutable bool
}

BlobSpec represents a file by HashKey and/or Blob.

func (*BlobSpec) Init

func (b *BlobSpec) Init(ctx context.Context, client filepb.FileServiceClient) error

Init initializes BlobSpec from HashKey or Blob. Either HashKey or Blob must be set before initialization.

type Disk

type Disk struct {
	Client filepb.FileServiceClient
}

Disk provides convenient methods to convert between local file and FileBlob in goma file service.

func (Disk) FromLocal

func (d Disk) FromLocal(ctx context.Context, fname string, spec *BlobSpec) error

FromLocal fills spec from fname.

func (Disk) ToLocal

func (d Disk) ToLocal(ctx context.Context, spec *BlobSpec, fname string) error

ToLocal creates file named fname from spec.

type LocalCache

type LocalCache struct {
	// Client is goma file service client.
	// If it is nil, it only uses local disk cache.
	Client filepb.FileServiceClient

	// Dir is a directory for local disk cache.
	Dir string
}

LocalCache is a goma file service with local disk cache.

func (LocalCache) LookupFile

func (c LocalCache) LookupFile(ctx context.Context, req *gomapb.LookupFileReq, opts ...grpc.CallOption) (*gomapb.LookupFileResp, error)

LookupFile looks up FileBlob for requested hash keys. It it is found in local disk cache, it will be used. Otherwise and c.Client is not nil, ask c.Client.

func (LocalCache) StoreFile

func (c LocalCache) StoreFile(ctx context.Context, req *gomapb.StoreFileReq, opts ...grpc.CallOption) (*gomapb.StoreFileResp, error)

StoreFile stores FileBlob in local disk, and c.Client if c.Client is not nil.

type Service

type Service struct {
	filepb.UnimplementedFileServiceServer
	// Cache is a fileblob storage.
	Cache cachepb.CacheServiceClient
}

Service represents goma file service.

func (*Service) LookupFile

func (s *Service) LookupFile(ctx context.Context, req *gomapb.LookupFileReq) (*gomapb.LookupFileResp, error)

LookupFile looks up FileBlob.

func (*Service) StoreFile

func (s *Service) StoreFile(ctx context.Context, req *gomapb.StoreFileReq) (*gomapb.StoreFileResp, error)

StoreFile stores FileBlob.

Jump to

Keyboard shortcuts

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