encoder

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 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

encoder

编码实现统一放在本包,独立于存储、解码器和 worker 协议。全部使用纯 Go。

实现 创建方式 输出
Gzip encoder.NewGzip(level) 标准 gzip
LZ4 encoder.LZ4{} 带校验的独立块帧
Zstd encoder.NewZstd(level) 标准 Zstandard 帧
MinLZ encoder.NewMinLZ(level) 带校验的独立流
Raw encoder.Raw{} 原始字节
enc, err := encoder.NewGzip(1)
if err != nil {
    return err
}
stats, err := enc.Encode(ctx, raw, dst)

导入路径为 github.com/lfhy/compactfs/codec/encoder。统一的 encoder.Encoder 接口包含 Name、Encode;encoder.Stats 返回格式名、原始长度和存储长度。

gzip 和 MinLZ 的编码器保留有界的空闲状态池。实例可用于独立流的并发编码, 公开的 Level 仅允许在调用之间修改,不要复制已使用的 MinLZ 实例。

只需要解压时使用 decoder。存储层、worker 和 FPGA 调度使用 codec 组合编码器与解码器。

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Name() string
	Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)
}

Encoder compresses one bounded, read-only chunk.

type Gzip

type Gzip struct {
	Level int
	// contains filtered or unexported fields
}

Gzip encodes standard gzip with pure Go and retains at most four idle encoders. Level may change between calls, but not during concurrent calls.

func NewGzip

func NewGzip(level int) (*Gzip, error)

func (*Gzip) Encode

func (g *Gzip) Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)

func (*Gzip) Name

func (g *Gzip) Name() string

type LZ4

type LZ4 struct{}

LZ4 encodes standard checksummed independent-block frames without cgo.

func (LZ4) Encode

func (l LZ4) Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)

func (LZ4) Name

func (LZ4) Name() string

type MinLZ

type MinLZ struct {
	Level int
	// contains filtered or unexported fields
}

MinLZ encodes independent, checksummed streams without cgo. A zero Level selects Fastest; -1, 1, 2 and 3 are the official levels. Level may change between calls, but must not change during concurrent calls. Do not copy a MinLZ after its first use.

func NewMinLZ

func NewMinLZ(level int) (*MinLZ, error)

func (*MinLZ) Encode

func (m *MinLZ) Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)

func (*MinLZ) Name

func (*MinLZ) Name() string

type Raw

type Raw struct{}

Raw writes an uncompressed chunk byte-for-byte.

func (Raw) Encode

func (Raw) Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)

func (Raw) Name

func (Raw) Name() string

type Stats

type Stats struct {
	Name       string
	RawSize    int64
	StoredSize int64
}

Stats describes the representation written by an encoder.

type Zstd

type Zstd struct {
	Level int
}

Zstd is the pure-Go Zstandard chunk encoder. Level is expressed using the usual zstd scale: values below 3 select the fastest mode, 3-5 select the default mode, 6-9 select better compression, and higher values select the best available mode. A zero level selects the fastest mode for write-back workloads.

func NewZstd

func NewZstd(level int) (*Zstd, error)

NewZstd creates a Zstandard encoder. The implementation maps the numeric zstd level to the stable encoder modes provided by klauspost/compress, so upgrades do not silently depend on its internal level table.

func (*Zstd) Encode

func (z *Zstd) Encode(ctx context.Context, raw []byte, dst io.Writer) (Stats, error)

func (*Zstd) Name

func (z *Zstd) Name() string

Jump to

Keyboard shortcuts

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