replace

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package replace 提供 OFD 包内条目的替换、新增与删除能力。

替换按包内路径(如 "Doc_0/Pages/Page_0/Content.xml")操作,不解析页面或 资源模型:命中的条目用新字节覆盖,其余条目原样搬运。由于任何字节改动都会 使已有签名摘要失效,Options.Signatures 默认丢弃签名目录;需要保留时可显式 选择 preserve 或 rewrite。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Files

func Files(input any, operations []Operation, w io.Writer, options Options) error

Files 读取 input(文件路径、字节数据或 io.Reader),执行操作后写入 w。

func Paths

func Paths(input any, files map[string]string, w io.Writer, options Options) error

Paths 是便捷入口:把所有 name->本地文件 映射作为 Set 操作执行。

Types

type Limits

type Limits = creator.Limits

Limits 限制输入与输出的规模,避免恶意或异常文档造成的解压放大。

type Operation

type Operation struct {
	// Kind 是操作类型。
	Kind OperationKind
	// Name 是包内路径,不带前导斜杠。
	Name string
	// Data 是 Set/Add 的新字节内容。
	Data []byte
}

Operation 描述一次条目操作。

type OperationKind

type OperationKind string

OperationKind 描述对某个包内条目的操作类型。

const (
	// OpSet 替换已有条目,条目不存在时报错。
	OpSet OperationKind = "set"
	// OpAdd 新增条目,条目已存在时报错。
	OpAdd OperationKind = "add"
	// OpDelete 删除已有条目,条目不存在时报错。
	OpDelete OperationKind = "delete"
)

type Options

type Options struct {
	// Compression 是输出 ZIP 的压缩策略,空值时按条目类型自动选择。
	Compression creator.CompressionMode
	// CompressionLevel 是 DEFLATE 压缩级别,0 使用默认级别 5,显式范围
	// 1(最快)到 9(最紧凑)。仅对实际使用 Deflate 的条目生效。
	CompressionLevel int
	// Deterministic 使用固定 ZIP 时间,生成可复现的结果。
	Deterministic bool
	// Signatures 是签名处理方式,空值跳过签名处理。
	Signatures creator.SignatureMode
	// Limits 限制输入与输出的规模,零值使用默认限制。
	Limits Limits
	// Validate 在输出后执行严格 OFD 校验。
	Validate bool
	// SkipXMLCheck 关闭默认的 XML 良构检查;Set/Add 的新内容若命中 .xml 条目,
	// 默认会先解析校验,防止写入格式损坏的 XML。
	SkipXMLCheck bool
	// OnWarning 可选,接收非致命提示,例如签名被保留但摘要已失效。
	OnWarning func(string)
}

Options 控制替换输出方式。

Jump to

Keyboard shortcuts

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