storage

package
v0.22.12 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataFileExtension string = ".data"
	CRCFileExtension  string = ".crc"
)

Variables

View Source
var (
	ErrorReadCRCFile = errors.New("failed to read crc file")
	ErrorParseCRC    = errors.New("failed to parse crc content")
	ErrorInvalidCRC  = errors.New("invalid crc content")
	ErrorVerifyCRC   = errors.New("error verifying crc of file")
)
View Source
var (
	ErrorOpenDataFile = errors.New("error opening data file")
	ErrorReadDataFile = errors.New("error opening data file")
)
View Source
var (
	Path = "../../data/"
)

Functions

func Checksum

func Checksum(data []byte) uint32

Checksum 计算标准的 IEEE802.3 CRC 结果

func CreateStoragePath

func CreateStoragePath()

func GetCRCFilePath

func GetCRCFilePath(fid string) string

GetCRCFilePath 获取一个crc文件的路径

func ParseDataFilename

func ParseDataFilename(fileBaseName string) (fid string, blockIndex int)

parseDataFilename 解析数据文件的文件名+扩展名部分,并返回 FID 和 文件的块序号

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile 读取一个磁盘文件

func VerifyBlockCRC

func VerifyBlockCRC(blockIndex int, block []byte, crcArray []uint32) bool

VerifyBlockCRC 校验一个2MB数据块(读出或写入)的CRC值

Types

type File

type File struct {
	Files []Item `json:"files"`
}

type Item

type Item struct {
	FileLen  int64    `json:"file_len"`
	FileName string   `json:"file_name"`
	FilePath string   `json:"file_path"`
	FID      string   `json:"fid"`
	CRCArray []uint32 `json:"crc_array"`
}

func LoadCRCFromFile

func LoadCRCFromFile(rid string) (*Item, error)

LoadCRCFromFile 从磁盘加载 CRC 信息到内存索引 若发现已存在则直接返回

func ParseCRC

func ParseCRC(rid string, content []byte) (*Item, error)

ParseCRC 从json格式的内容中解析出 CRC 数组并添加到索引

Jump to

Keyboard shortcuts

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