decoder

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: ? 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.

README

decoder

解码实现统一放在本包,独立于存储、编码器和 worker 协议。全部使用纯 Go。 按已存储的数据格式选择解码器,CPU 与 FPGA 生成的同格式数据共用对应实现。

实现 创建方式 输入
Gzip decoder.Gzip{} 标准 gzip,含固定/动态 Huffman、stored 和多 member
LZ4 decoder.LZ4{} 标准帧,含 FPGA 的未压缩块回退
Zstd decoder.Zstd{} 标准 Zstandard 帧
MinLZ decoder.MinLZ{} CPU/FPGA 的带校验独立流
Raw decoder.Raw{} 原始字节
dec := decoder.Gzip{}
err := dec.Decode(ctx, src, dst)

// 已有完整 gzip 字节切片时,可直接提交,无需创建 reader。
err = dec.DecodeBytes(ctx, encoded, dst)

导入路径为 github.com/lfhy/compactfs/codec/decoder。统一的 decoder.Decoder 接口包含 Name、Decode。只需要压缩时使用 encoder。

gzip 快速路径使用 64 位位缓冲、32 位批量取数、小型固定码表、三字面量批处理, 以及支持重叠的 LZ77 批量复制。完整核对成员边界、ISIZE 和 CRC 后才写入目标; 保留取消、目标写入错误和短写检查。

bytes.Reader / bytes.Buffer 可直接暴露完整输入切片,无需复制输入。 普通文件、网络等 reader 使用通用流式解码器。每次 gzip 快速解码输出最多 decoder.MaxGzipFastSize(16 MiB),四个空闲槽位最多保留 64 MiB;更大的 合法数据通过通用流式解码读取。输入切片不会保存在池中。

遇到动态 Huffman 或混合码流时,快速路径在写入目标前回退通用解码器, 不会重复输出前面的固定块。测试条件和性能。

codec 将本包与编码器组合,供 chunk store、FUSE、NBD 和独立 worker 使用;无需为 gzip 快速路径新增配置。

Documentation

Overview

Package decoder implements pure Go chunk decoders independently of storage, worker protocols, and the corresponding encoders.

Index

Constants

View Source
const MaxGzipFastSize = 16 << 20

MaxGzipFastSize bounds speculative output allocation, including corrupt ISIZE fields. Larger chunks still decode through the general streaming path.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Name() string
	Decode(ctx context.Context, src io.Reader, dst io.Writer) error
}

Decoder restores one stored chunk. Its name describes the wire format, independently of whether CPU or FPGA hardware originally encoded the chunk.

type Gzip

type Gzip struct{}

Gzip decodes standard gzip, using a bounded fixed-Huffman fast path for complete chunks and the general pure Go decoder for other streams.

func (Gzip) Decode

func (Gzip) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

Decode decodes a gzip reader. bytes.Reader and bytes.Buffer expose a complete chunk to DecodeBytes through WriteTo without copying their backing slice. Other readers use the general streaming decoder, with no whole-input buffering.

func (Gzip) DecodeBytes

func (Gzip) DecodeBytes(ctx context.Context, encoded []byte, dst io.Writer) error

DecodeBytes decodes a complete gzip byte slice. It accepts concatenated members, optional headers, and all standard DEFLATE block types. The fast path never publishes bytes until the entire member's size and CRC have been verified. Callers must not modify encoded during the call.

func (Gzip) Name

func (Gzip) Name() string

type LZ4

type LZ4 struct{}

LZ4 accepts standard independent-block frames, including the FPGA profile's checksummed frames and uncompressed-block fallback.

func (LZ4) Decode

func (LZ4) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

func (LZ4) Name

func (LZ4) Name() string

type MinLZ

type MinLZ struct{}

MinLZ restores independent checksummed streams from CPU or FPGA encoders.

func (MinLZ) Decode

func (MinLZ) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

func (MinLZ) Name

func (MinLZ) Name() string

type Raw

type Raw struct{}

Raw copies an uncompressed chunk byte-for-byte.

func (Raw) Decode

func (Raw) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

func (Raw) Name

func (Raw) Name() string

type Zstd

type Zstd struct{}

Zstd decodes standard Zstandard frames without cgo.

func (Zstd) Decode

func (Zstd) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

func (Zstd) Name

func (Zstd) Name() string

Jump to

Keyboard shortcuts

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