chunk

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chunk 提供分片大小推导与内容摘要计算。

Index

Constants

View Source
const (
	// MB 1MB 字节数
	MB = 1 << 20

	// MinChunkSize 全局分片下限 5MB。
	MinChunkSize = 5 * MB

	// MaxChunkCount 单个 multipart 上传的最大片数(厂商硬上限,已吸收进 Size 公式而非事后判)
	MaxChunkCount = 10000

	// MaxTotalSize 单文件物理天花板(字节)= 4095 × 1MB × 10000 ≈ 42.94 TB。
	MaxTotalSize = 4095 * 10000 * MB
)

Variables

View Source
var (
	// ErrEmptyFile 空文件
	ErrEmptyFile = errors.New("chunk: 不支持空文件")

	// ErrFileTooLarge 超过 MaxTotalSize(物理天花板)
	ErrFileTooLarge = errors.New("chunk: 文件过大")

	// ErrEmptyDigest 分片摘要序列为空
	ErrEmptyDigest = errors.New("chunk: 分片摘要为空")

	// ErrInvalidDigest 分片摘要非法:不是 32 位小写 hex,或片号重复/为 0
	ErrInvalidDigest = errors.New("chunk: 分片摘要非法")
)

Functions

func Count

func Count(totalSize uint64, chunkSize uint32) uint32

Count 推导片数:ceilDiv(totalSize, chunkSize);chunkSize 为 0 时返回 0。

func Digest

func Digest(parts []Part) (string, error)

Digest 计算内容摘要:按片号升序拼接各片摘要的 hex 文本再取 MD5;单片 N=1 同规(对文件 md5 再取一次 md5)。

func NormalizeETag

func NormalizeETag(etag string) string

NormalizeETag 归一化厂商分片 ETag:剥掉包裹的双引号、去空白、转小写,得到可直接参与聚合的 hex。

func Size

func Size(totalSize uint64) (uint32, error)

Size 推导分片大小:max(5MB, ceilDiv(totalSize, 10000*MB) * MB);超过天花板返回 error,不静默截断。

Types

type Part

type Part struct {
	Number uint32 // 片号,从 1 起
	Digest string // 该片内容摘要(32 位小写 hex)
}

Part 分片摘要:片号(从 1 起)+ 该片内容摘要(32 位小写 hex)。

Jump to

Keyboard shortcuts

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