checksum

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package checksum 校验本地文件包

Index

Constants

View Source
const (
	// CHECKSUM_MD5 获取文件的 md5 值
	CHECKSUM_MD5 int = 1 << iota
	// CHECKSUM_SLICE_MD5 获取文件前 sliceSize 切片的 md5 值
	CHECKSUM_SLICE_MD5
	// CHECKSUM_CRC32 获取文件的 crc32 值
	CHECKSUM_CRC32
)
View Source
const (
	// DefaultBufSize 默认的bufSize
	DefaultBufSize = int(256 * converter.KB)
)

Variables

View Source
var (
	ErrFileIsNil            = errors.New("file is nil")
	ErrChecksumWriteStop    = errors.New("checksum write stop")
	ErrChecksumWriteAllStop = errors.New("checksum write all stop")
)

Functions

This section is empty.

Types

type ChecksumWriteUnit

type ChecksumWriteUnit struct {
	SliceEnd       int64
	End            int64
	SliceSum       interface{}
	Sum            interface{}
	OnlySliceSum   bool
	ChecksumWriter ChecksumWriter
	// contains filtered or unexported fields
}

func (*ChecksumWriteUnit) Write

func (wi *ChecksumWriteUnit) Write(p []byte) (n int, err error)

type ChecksumWriter

type ChecksumWriter interface {
	io.Writer
	Sum() interface{}
}

func NewHash32ChecksumWriter

func NewHash32ChecksumWriter(h32 hash.Hash32) ChecksumWriter

func NewHashChecksumWriter

func NewHashChecksumWriter(h hash.Hash) ChecksumWriter

type LocalFileChecksum

type LocalFileChecksum struct {
	LocalFileMeta
	// contains filtered or unexported fields
}

LocalFileChecksum 校验本地文件

func GetFileSum

func GetFileSum(localPath string, flag int) (lfc *LocalFileChecksum, err error)

GetFileSum 获取文件的大小, md5, 前256KB切片的 md5, crc32

func NewLocalFileChecksum

func NewLocalFileChecksum(localPath string, sliceSize int) *LocalFileChecksum

func NewLocalFileChecksumWithBufSize

func NewLocalFileChecksumWithBufSize(localPath string, bufSize, sliceSize int) *LocalFileChecksum

func (*LocalFileChecksum) Close

func (lfc *LocalFileChecksum) Close() error

Close 关闭文件

func (*LocalFileChecksum) GetFile

func (lfc *LocalFileChecksum) GetFile() *os.File

GetFile 获取文件

func (*LocalFileChecksum) OpenPath

func (lfc *LocalFileChecksum) OpenPath() error

OpenPath 检查文件状态并获取文件的大小 (Length)

func (*LocalFileChecksum) Sum

func (lfc *LocalFileChecksum) Sum(checkSumFlag int) (err error)

Sum 计算文件摘要值

type LocalFileMeta

type LocalFileMeta struct {
	Path     string `json:"path"`     // 本地路径
	Length   int64  `json:"length"`   // 文件大小
	SliceMD5 []byte `json:"slicemd5"` // 文件前 requiredSliceLen (256KB) 切片的 md5 值
	MD5      []byte `json:"md5"`      // 文件的 md5
	CRC32    uint32 `json:"crc32"`    // 文件的 crc32
	ModTime  int64  `json:"modtime"`  // 修改日期
}

LocalFileMeta 本地文件元信息

func (*LocalFileMeta) CompleteAbsPath

func (lfm *LocalFileMeta) CompleteAbsPath()

CompleteAbsPath 补齐绝对路径

func (*LocalFileMeta) EqualLengthMD5

func (lfm *LocalFileMeta) EqualLengthMD5(m *LocalFileMeta) bool

EqualLengthMD5 检测md5和大小是否相同

Jump to

Keyboard shortcuts

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