DocTrim

package module
v0.0.0-...-50598e4 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 14 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

DocTrim

Compress ooxml file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyToSelfClosing

func EmptyToSelfClosing(from []byte) []byte

func EqualXml

func EqualXml(l, r []byte) bool

func NodeEquals

func NodeEquals(l, r *Node) bool

Types

type DocTrim

type DocTrim struct {
	// contains filtered or unexported fields
}

Slimmer 精简器

func (*DocTrim) MakeReader

func (s *DocTrim) MakeReader(url string) (*zip.ReadCloser, error)

MakeReader 根据URL创建zip.ReadCloser对象 如果URL以http://或https://开头,则下载文件并返回ReadCloser对象 否则,打开本地文件并返回ReadCloser对象

func (*DocTrim) Pack

func (slim *DocTrim) Pack(xmlData io.Reader) ([]byte, error)

Pack 压缩XML 使用xml.Decoder将XML解码为Node对象 然后计算节点的哈希值,并压缩节点及其子节点 最后,使用xml.Marshal将Node对象转换为XML字节数组并返回

func (DocTrim) Process

func (s DocTrim) Process(url string) ([]byte, error)

Process 处理文档 根据URL打开或下载文件,并遍历zip文件中的文件 如果找到"word/document.xml"文件,则读取其内容并返回 否则,返回空字符串

func (*DocTrim) RegHash

func (slim *DocTrim) RegHash(hash uint64, node *Node) (uint64, bool)

func (*DocTrim) Reset

func (slim *DocTrim) Reset()

func (DocTrim) Unpack

func (s DocTrim) Unpack(reader io.Reader) ([]byte, error)

Unpack 解压缩XML 使用xml.Decoder将XML解码为Node对象 然后计算节点的哈希值,并压缩节点及其子节点 最后,使用xml.Marshal将Node对象转换为XML字节数组并返回

type Node

type Node struct {
	XMLName  xml.Name
	Attrs    []xml.Attr `xml:",any,attr"`
	Content  []byte     `xml:",chardata"`
	Children []*Node    `xml:",any"`
	// contains filtered or unexported fields
}

Node 表示XML节点

func (*Node) Compact

func (node *Node) Compact() error

Compact 压缩节点 如果节点的isCompat字段为true,则将节点的属性、内容和子节点清空 否则,如果节点的refCount大于0,则将节点的哈希值作为属性添加到节点中 最后,递归压缩子节点

func (*Node) ComputeHash

func (node *Node) ComputeHash(slim *DocTrim) uint64

ComputeHash 计算节点的哈希值 使用fnv算法计算节点的哈希值,并将结果存储在hash字段中 如果哈希值已存在于字典中,则将节点的isCompat字段设置为true

func (*Node) Marshal

func (node *Node) Marshal() ([]byte, error)

Marshal 将节点转换为XML字节数组

func (*Node) OmitNode

func (node *Node) OmitNode()

func (*Node) UndoCompact

func (node *Node) UndoCompact(dict map[uint64]*Node) error

Jump to

Keyboard shortcuts

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