file

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinBlockSize uint32 = 1000000
	MaxBlockSize uint32 = 8000000

	// S_IFREG is the regular file type
	S_IFREG = 0100000
)

Variables

View Source
var (

	// ErrFileAlreadyPresent denotes file is present
	ErrFileAlreadyPresent = errors.New("file already present in the destination dir")

	// ErrFileNotFound denotes file is not found in dfs
	ErrFileNotFound = errors.New("file not found in dfs")

	// ErrFileTagPresent denotes file status is not available
	ErrFileTagPresent = errors.New("file status is not available")
)
View Source
var (
	// MetaVersion is the version of the meta data
	MetaVersion uint8 = 2

	// ErrDeletedFeed is returned when the feed is deleted
	ErrDeletedFeed = errors.New("deleted feed")

	// ErrUnknownFeed is returned when the feed is unknown
	ErrUnknownFeed = errors.New("unknown value in feed")
)
View Source
var (
	ErrInvalidBlockSize = fmt.Errorf("upload: block size must be between %d - %d (1Mb - 8Mb)", MinBlockSize, MaxBlockSize)
)
View Source
var (
	// ErrInvalidOffset is returned when the offset is invalid
	ErrInvalidOffset = errors.New("invalid offset")
)

Functions

func Compress

func Compress(dataToCompress []byte, compression string, blockSize uint32) ([]byte, error)

Compress data

func Decompress

func Decompress(dataToDecompress []byte, compression string, blockSize uint32) ([]byte, error)

Decompress decompresses the data

Types

type BlockInfo added in v0.5.3

type BlockInfo struct {
	Size           uint32          `json:"size"`
	CompressedSize uint32          `json:"compressedSize"`
	Reference      utils.Reference `json:"reference"`
}

BlockInfo is the structure of the block info

type Entry added in v0.5.3

type Entry struct {
	Name             string `json:"name"`
	ContentType      string `json:"contentType"`
	Size             string `json:"size,omitempty"`
	BlockSize        string `json:"blockSize,omitempty"`
	CreationTime     string `json:"creationTime"`
	ModificationTime string `json:"modificationTime"`
	AccessTime       string `json:"accessTime"`
	Mode             uint32 `json:"mode"`
}

Entry is the structure of the entry

type File

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

File represents a file in a pod

func NewFile

func NewFile(podName string, client blockstore.Client, fd *feed.API, user utils.Address,
	m taskmanager.TaskManagerGO, logger logging.Logger) *File

NewFile creates the base file object which has all the methods related to file manipulation.

func (*File) AddToFileMap

func (f *File) AddToFileMap(filePath string, meta *MetaData)

AddToFileMap adds a file metadata into fileMap

func (*File) AddToTagMap added in v0.9.2

func (f *File) AddToTagMap(filePath string, tag uint32)

AddToTagMap adds a mapping filename and tag into tagMap

func (*File) BackupFromFileName added in v0.7.0

func (f *File) BackupFromFileName(fileNameWithPath, podPassword string) (*MetaData, error)

BackupFromFileName is used to backup a file

func (*File) Chmod added in v0.9.2

func (f *File) Chmod(podFileWithPath, podPassword string, mode uint32) error

Chmod does all the validation for the existence of the file and changes file mode

func (*File) DeleteFromTagMap added in v0.9.2

func (f *File) DeleteFromTagMap(filePath string)

DeleteFromTagMap deletes a tag from tagMap

func (*File) Download

func (f *File) Download(podFileWithPath, podPassword string) (io.ReadCloser, uint64, error)

Download does all the validation for the existence of the file and creates a Reader to read the contents of the file from the pod.

func (*File) GetFromFileMap

func (f *File) GetFromFileMap(filePath string) *MetaData

GetFromFileMap gets file metadata from the fileMap

func (*File) GetInode added in v0.9.3

func (f *File) GetInode(podPassword, filePath string) *MetaData

func (*File) GetMetaFromFileName added in v0.5.3

func (f *File) GetMetaFromFileName(fileNameWithPath, podPassword string, userAddress utils.Address) (*MetaData, error)

GetMetaFromFileName is used to get meta from file name

func (*File) GetStats added in v0.5.3

func (f *File) GetStats(podName, podFileWithPath, podPassword string) (*Stats, error)

GetStats given a filename this function returns all the information about the file including the block information.

func (*File) IsFileAlreadyPresent added in v0.5.3

func (f *File) IsFileAlreadyPresent(podPassword, fileWithPath string) bool

IsFileAlreadyPresent checks if a file is present in the fileMap

func (*File) ListFiles

func (f *File) ListFiles(files []string, podPassword string) ([]Entry, error)

ListFiles given a list of files, list files gives back the information related to each file.

func (*File) LoadFileMeta

func (f *File) LoadFileMeta(fileNameWithPath, podPassword string) error

LoadFileMeta is used in syncing

func (*File) LoadFromTagMap added in v0.9.2

func (f *File) LoadFromTagMap(filePath string) uint32

LoadFromTagMap gets a tag from tagMap

func (*File) OpenFileForIndex

func (f *File) OpenFileForIndex(podFile, podPassword string) (*Reader, error)

OpenFileForIndex opens file for indexing for document db from pod filepath TODO test skipcq: TCV-001

func (*File) PutMetaForFile added in v0.6.2

func (f *File) PutMetaForFile(meta *MetaData, podPassword string) error

PutMetaForFile is used to put meta for a file

func (*File) ReadSeeker added in v0.9.1

func (f *File) ReadSeeker(podFileWithPath, podPassword string) (io.ReadSeekCloser, uint64, error)

ReadSeeker does all the validation for the existence of the file and creates a ReadSeekCloser to read the contents of the file from the pod.

func (*File) RemoveAllFromFileMap added in v0.5.3

func (f *File) RemoveAllFromFileMap()

RemoveAllFromFileMap resets the fileMap

func (*File) RemoveFromFileMap

func (f *File) RemoveFromFileMap(filePath string)

RemoveFromFileMap removes a file metadata from fileMap

func (*File) RenameFromFileName added in v0.9.1

func (f *File) RenameFromFileName(fileNameWithPath, newFileNameWithPath, podPassword string) (*MetaData, error)

RenameFromFileName is used to rename a file

func (*File) RmFile added in v0.5.3

func (f *File) RmFile(podFileWithPath, podPassword string) error

RmFile deletes all the blocks of a file, and it related metadata from the Swarm network.

func (*File) Status added in v0.9.2

func (f *File) Status(podFileWithPath, podPassword string) (int64, int64, int64, error)

Status does all the validation for the existence of the file and checks file sync status

func (*File) Upload

func (f *File) Upload(fd io.Reader, podFileName string, fileSize int64, blockSize, mode uint32, podPath, compression, podPassword string) error

Upload uploads a given blob of bytes as a file in the pod. It also splits the file into number of blocks. the size of the block is provided during upload. This function also does compression of the blocks gzip/snappy if it is requested during the upload.

func (*File) WriteAt added in v0.9.1

func (f *File) WriteAt(podFileWithPath, podPassword string, update io.Reader, offset uint64, truncate bool) (int, error)

WriteAt writes a file from a given offset

type IFile added in v0.5.3

type IFile interface {
	Upload(fd io.Reader, podFileName string, fileSize int64, blockSize, mode uint32, podPath, compression, podPassword string) error
	Download(podFileWithPath, podPassword string) (io.ReadCloser, uint64, error)
	ListFiles(files []string, podPassword string) ([]Entry, error)
	GetStats(podName, podFileWithPath, podPassword string) (*Stats, error)
	RmFile(podFileWithPath, podPassword string) error
	LoadFileMeta(fileNameWithPath, podPassword string) error
}

IFile is the interface for file operations

type INode added in v0.5.3

type INode struct {
	Blocks []*BlockInfo `json:"blocks"`
}

INode is the structure of the inode

type MetaData added in v0.5.3

type MetaData struct {
	Version          uint8  `json:"version"`
	Path             string `json:"filePath"`
	Name             string `json:"fileName"`
	Size             uint64 `json:"fileSize"`
	BlockSize        uint32 `json:"blockSize"`
	ContentType      string `json:"contentType"`
	Compression      string `json:"compression"`
	CreationTime     int64  `json:"creationTime"`
	AccessTime       int64  `json:"accessTime"`
	ModificationTime int64  `json:"modificationTime"`
	InodeAddress     []byte `json:"fileInodeReference"`
	Mode             uint32 `json:"mode"`
}

MetaData is the structure of the file metadata

type Reader

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

Reader is a struct to read a file from the pod

func NewReader

func NewReader(fileInode INode, client blockstore.Client, fileSize uint64, blockSize uint32, compression string, cache bool) *Reader

NewReader create a new reader object to read a file from the pod based on its configuration.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the reader

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

Read reads a given segment of the file from the pod and returns it. it does all the related function like block extraction, block un-compression etc.

func (*Reader) ReadLine

func (r *Reader) ReadLine() ([]byte, error)

ReadLine reads a line from the file

func (*Reader) Seek

func (r *Reader) Seek(seekOffset int64, _ int) (int64, error)

Seek seeks to a given offset in the file and returns the offset.

type Stats added in v0.5.3

type Stats struct {
	PodName          string `json:"podName"`
	Mode             uint32 `json:"mode"`
	FilePath         string `json:"filePath"`
	FileName         string `json:"fileName"`
	FileSize         string `json:"fileSize"`
	BlockSize        string `json:"blockSize"`
	Compression      string `json:"compression"`
	ContentType      string `json:"contentType"`
	CreationTime     string `json:"creationTime"`
	ModificationTime string `json:"modificationTime"`
	AccessTime       string `json:"accessTime"`
}

Stats is the structure of the file stats

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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