file

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DEFAULT_EXP_THRESHOLD = 2 // 2 days (will delete if no visit since 2 days ago)
)
View Source
const HLS_HEADER_FILENAME = "index.m3u8"
View Source
const HLS_SEGMENT_FILENAME = "%d.ts"
View Source
const (
	LOCAL_TAG = "LOCAL"
)
View Source
const NUMBER_OF_UPLOAD_CHAN_BUFFER = 5
View Source
const TEMP_FOLDER = "tmp"
View Source
const TMP_FOLDER_VIDEO = "video"

Variables

View Source
var (
	DataBuffer sync.Mutex
)
View Source
var (

	// wait for the next request from client per message
	RpcWaitTimeout time.Duration
)

Functions

func CacheRemoteFileData added in v0.10.0

func CacheRemoteFileData(fileHash string, offset *protos.SliceOffset, folderName, fileName string, writeFromStartOffset bool) error

func CheckDownloadCache added in v0.11.0

func CheckDownloadCache(fileHash string) error

CheckDownloadCache check there is download cache for the file with fileHash

func CheckFileExisting

func CheckFileExisting(ctx context.Context, fileHash, fileName, savePath, encryptionTag, fileReqId string) bool

func CheckFilePathEx

func CheckFilePathEx(filePath string) bool

func CheckSliceExisting

func CheckSliceExisting(fileHash, fileName, sliceHash, fileReqId string) bool

func CleanFileHash added in v0.9.0

func CleanFileHash(key string)

func ClearFileMap

func ClearFileMap(hash string)

func CloseDownloadSession added in v0.9.0

func CloseDownloadSession(key string)

func CopyDownloadFile added in v0.11.0

func CopyDownloadFile(fileHash, fileName, savePath string) error

func CreateFolderAndReopenFile added in v0.11.0

func CreateFolderAndReopenFile(folderPath, fileName string) (*os.File, error)

func CreateTarWithZstd added in v0.10.0

func CreateTarWithZstd(source string, target string) error

func DeleteDirectory

func DeleteDirectory(fileHash string)

func DeleteSlice

func DeleteSlice(sliceHash string) error

func DeleteTmpFileSlices added in v0.8.0

func DeleteTmpFileSlices(ctx context.Context, fileHash string)

func DeleteTmpHlsFolder added in v0.8.0

func DeleteTmpHlsFolder(ctx context.Context, fileHash string)

func EscapePath

func EscapePath(param []string) string

EscapePath

func ExtractTarWithZstd added in v0.10.0

func ExtractTarWithZstd(source string, target string) error

func FinishLocalDownload added in v0.11.0

func FinishLocalDownload(fileHash string)

FinishLocalDownload when a local download is done, successfully or unsuccessfully, call this to untag

func GetClearExpiredShareLinksResult added in v0.10.0

func GetClearExpiredShareLinksResult(key string) (*rpc.ClearExpiredShareLinksResult, bool)

func GetDownloadFileNameFromTmp added in v0.11.0

func GetDownloadFileNameFromTmp(fileHash string) (string, error)

GetDownloadFileNameFromTmp fetch the first name in download tmp folder with the filehash, and generate the file name

func GetDownloadFilePath added in v0.11.0

func GetDownloadFilePath(fileName, savePath string) string

GetDownloadFilePath path to a file as in download folder

func GetDownloadTmpCsvPath added in v0.11.0

func GetDownloadTmpCsvPath(fileHash, fileName string) string

GetDownloadTmpCsvPath get download CSV path

func GetDownloadTmpFilePath added in v0.11.0

func GetDownloadTmpFilePath(fileHash, fileName string) string

GetDownloadTmpFilePath path to the download tmp file

func GetDumpySliceData

func GetDumpySliceData(fileHash string, sliceNumber uint64) []byte

func GetFileData

func GetFileData(filePath string, offset *protos.SliceOffset) ([]byte, error)

func GetFileHash

func GetFileHash(filePath, encryptionTag string) string

func GetFileHashForVideoStream added in v0.10.0

func GetFileHashForVideoStream(filePath, encryptionTag string) string

func GetFileInfo

func GetFileInfo(filePath string) (os.FileInfo, error)

func GetFileListResult added in v0.9.0

func GetFileListResult(key string) (*rpc.FileListResult, bool)

func GetFileName added in v0.11.0

func GetFileName(fileHash string) string

func GetFilePath

func GetFilePath(hash string) string

func GetFileShareResult added in v0.9.0

func GetFileShareResult(key string) (*rpc.FileShareResult, bool)

func GetFileSuffix

func GetFileSuffix(fileName string) string

func GetQueryOzoneResult added in v0.9.0

func GetQueryOzoneResult(key string) (*rpc.GetOzoneResult, bool)

func GetRemoteFileData added in v0.9.0

func GetRemoteFileData(hash string, offset *protos.SliceOffset) []byte

GetRemoteFileData application calls this func to fetch a (sub)slice of file data from remote user

func GetRemoteFileInfo added in v0.9.0

func GetRemoteFileInfo(key, reqId string) uint64

func GetRemoteFileSize added in v0.9.0

func GetRemoteFileSize(hash string) uint64

func GetSignatureFromRemote added in v0.9.0

func GetSignatureFromRemote(key string) []byte

func GetSliceData

func GetSliceData(sliceHash string) ([]byte, error)

func GetSliceDataFromTmp added in v0.8.0

func GetSliceDataFromTmp(fileHash, sliceHash string) ([]byte, error)

func GetSliceSize

func GetSliceSize(sliceHash string) (int64, error)

func GetTmpDownloadPath added in v0.11.0

func GetTmpDownloadPath() string

GetTmpDownloadPath path to the download tmp file folder

func GetTmpFileFolderPath added in v0.10.0

func GetTmpFileFolderPath(fileHash string) string

GetTmpFileFolderPath path to tmp file folder for specific file

func GetTmpSlicePath added in v0.10.0

func GetTmpSlicePath(fileHash, sliceHash string) string

func GetVideoDuration

func GetVideoDuration(path string) (uint64, error)

func GetVideoTmpFolder

func GetVideoTmpFolder(fileHash string) string

func GetWholeFileData

func GetWholeFileData(filePath string) ([]byte, error)

func IsFile

func IsFile(f string) (bool, error)

IsFile checks if the path is a file or directory

func IsFileRpcRemote added in v0.9.0

func IsFileRpcRemote(key string) bool

func IsLocalDownload added in v0.11.0

func IsLocalDownload(fileHash string) bool

StartLocalDownload when a local download starts, call this to tag a local download is on

func OpenTmpFile added in v0.10.0

func OpenTmpFile(fileHash, fileName string) (*os.File, error)

func PathExists

func PathExists(path string) (bool, error)

pathExists

func ReadDownloadCachedData added in v0.11.0

func ReadDownloadCachedData(fileHash, reqid string) ([]byte, uint64, uint64, bool)

ReadDownloadCachedData read setting.MacData bytes from the cache and store the cursor for next reading; check the end if cursor equals file size.

func ReadFileDataToPackets added in v0.10.1

func ReadFileDataToPackets(r *mmap.ReaderAt, path string) (size int64, buffer [][]byte, err error)

func ReadSliceData added in v0.10.1

func ReadSliceData(fileHash, sliceHash string) (int64, [][]byte, error)

func ReadSliceDataFromTmp added in v0.10.1

func ReadSliceDataFromTmp(fileHash, sliceHash string) (int64, [][]byte, error)

func RecordDownloadCSV

func RecordDownloadCSV(target *protos.RspFileStorageInfo)

func RenameTmpFile added in v0.10.0

func RenameTmpFile(fileHash, srcFile, dstFile string) error

func RequestBuffersForSlice added in v0.10.1

func RequestBuffersForSlice(size int64) [][]byte

func SaveDownloadProgress

func SaveDownloadProgress(ctx context.Context, sliceHash, fileName, fileHash, savePath, fileReqId string)

func SaveDownloadedFileData added in v0.11.0

func SaveDownloadedFileData(data []byte, offset int64, sliceHash, fileName, fileHash, savePath, fileReqId string) error

SaveDownloadedFileData save data of downloaded file into download temporary folder

func SaveRemoteFileData added in v0.9.0

func SaveRemoteFileData(key, fileName string, data []byte, offset uint64) error

SaveRemoteFileData application calls this func to send a slice of file data to remote user during download process

func SaveRemoteFileHash added in v0.9.0

func SaveRemoteFileHash(hash, filePath string, fileSize uint64)

func SaveRemoteFileSliceData added in v0.10.0

func SaveRemoteFileSliceData(sliceKey, fileKey, fileName string, data []byte, offset uint64) error

func SaveRemoteSliceData added in v0.10.0

func SaveRemoteSliceData(key, fileName string, data []byte, offset uint64) error

SaveRemoteSliceData application calls this func to send a slice of file data to remote user during slice download process

func SaveSliceData

func SaveSliceData(data []byte, sliceHash string, offset uint64) error

func SaveTmpSliceData added in v0.8.0

func SaveTmpSliceData(fileHash, sliceHash string, data []byte) error

func SendFileDataBack added in v0.9.0

func SendFileDataBack(hash string, content []byte)

SendFileDataBack rpc server feeds file data from remote user to application

func SetClearExpiredShareLinksResult added in v0.10.0

func SetClearExpiredShareLinksResult(key string, result *rpc.ClearExpiredShareLinksResult)

func SetDownloadSliceDone added in v0.9.0

func SetDownloadSliceDone(key string)

SetDownloadSliceDone rpc server tells the remote user has received last downloaded slice

func SetFileListResult added in v0.9.0

func SetFileListResult(key string, result *rpc.FileListResult)

func SetFileShareResult added in v0.9.0

func SetFileShareResult(key string, result *rpc.FileShareResult)

func SetGetFileStatusDone added in v0.10.0

func SetGetFileStatusDone(key string, result *rpc.FileStatusResult)

func SetQueryOzoneResult added in v0.9.0

func SetQueryOzoneResult(key string, result *rpc.GetOzoneResult)

func SetRemoteFileInfo added in v0.9.0

func SetRemoteFileInfo(key string, size uint64)

func SetRemoteFileResult added in v0.9.0

func SetRemoteFileResult(key string, result rpc.Result)

SetRemoteFileResult application sends the result of previous operation to rpc server

func SetRemoteSliceResult added in v0.10.0

func SetRemoteSliceResult(key string, result rpc.Result)

SetRemoteSliceResult application sends the result to rpc server

func SetSignature added in v0.9.0

func SetSignature(key string, sig []byte)

func StartClearTmpFileJob added in v0.10.1

func StartClearTmpFileJob(ctx context.Context)

func StartLocalDownload added in v0.11.0

func StartLocalDownload(fileHash string)

StartLocalDownload when a local download starts, call this to tag a local download is on

func StopClearTmpFileJob added in v0.10.1

func StopClearTmpFileJob()

func SubscribeDownloadFileInfo added in v0.9.0

func SubscribeDownloadFileInfo(key string) chan uint64

func SubscribeDownloadSliceDone added in v0.9.0

func SubscribeDownloadSliceDone(key string) chan bool

func SubscribeGetFileStatusDone added in v0.10.0

func SubscribeGetFileStatusDone(key string) chan *rpc.FileStatusResult

func SubscribeGetRemoteFileData added in v0.9.0

func SubscribeGetRemoteFileData(key string) chan []byte

SubscribeGetRemoteFileData application subscribes to remote file data and waits for remote user's feedback

func SubscribeGetSignature added in v0.9.0

func SubscribeGetSignature(key string) chan []byte

func SubscribeRemoteFileEvent added in v0.9.0

func SubscribeRemoteFileEvent(key string) chan *rpc.Result

SubscribeRemoteFileEvent rpc server subscribes to events from application. Now, result of operation is the only event

func SubscribeRemoteSliceEvent added in v0.10.0

func SubscribeRemoteSliceEvent(key string) chan *rpc.Result

SubscribeRemoteSliceEvent rpc server subscribes to events from application. Now, result of operation is the only event

func UnsubscribeDownloadFileInfo added in v0.9.0

func UnsubscribeDownloadFileInfo(key string)

func UnsubscribeDownloadSliceDone added in v0.9.0

func UnsubscribeDownloadSliceDone(key string)

func UnsubscribeGetFileStatusDone added in v0.10.0

func UnsubscribeGetFileStatusDone(key string)

func UnsubscribeGetRemoteFileData added in v0.9.0

func UnsubscribeGetRemoteFileData(key string)

UnsubscribeGetRemoteFileData unsubscribe after the application finishes receiving the slice of file data

func UnsubscribeGetSignature added in v0.9.0

func UnsubscribeGetSignature(key string)

func UnsubscribeRemoteFileEvent added in v0.9.0

func UnsubscribeRemoteFileEvent(key string)

UnsubscribeRemoteFileEvent rpc server unsubscribes to event from application. Now, result of operation is the only event

func UnsubscribeRemoteSliceEvent added in v0.10.0

func UnsubscribeRemoteSliceEvent(key string)

UnsubscribeRemoteSliceEvent rpc server unsubscribes to event from application. Now, result of operation is the only event

func VideoToHls

func VideoToHls(ctx context.Context, fileHash, filePath string) bool

func WaitDownloadSliceDone added in v0.9.0

func WaitDownloadSliceDone(key string) error

WaitDownloadSliceDone application waits for remote user to tell that the downloaded slice received

func WriteFile added in v0.10.0

func WriteFile(data []byte, offset int64, fileMg *os.File) error

Types

type HlsInfo

type HlsInfo struct {
	FileHash         string
	HeaderFile       string
	StartSliceNumber uint64
	SegmentToSlice   map[string]uint64
	SliceToSegment   map[uint64]string
}

func GetHlsInfo

func GetHlsInfo(fileHash string, maxSliceCount uint64) (*HlsInfo, error)

func LoadHlsInfo

func LoadHlsInfo(fileHash, sliceHash, savePath string) *HlsInfo

func LoadHlsInfoFromData added in v0.10.0

func LoadHlsInfoFromData(data []byte) (*HlsInfo, error)

Jump to

Keyboard shortcuts

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