archive

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Overview

Package archive 提供 OFD 文档的档案预检、清单和归档准备辅助功能。 它不会修改源 OFD,也不宣称文档符合法律或合规要求。

Index

Constants

View Source
const (
	// SchemaVersion 是归档清单与报告的模式版本。
	//
	// 它是格式版本,与发行版本无关:清单或报告结构变了才改,工具发版不改。归档
	// verify 会比对报告里的这个值,因此改它等于作废此前生成的归档。
	SchemaVersion = "1"

	StatusPassed      = "passed"
	StatusWarning     = "warning"
	StatusFailed      = "failed"
	StatusNotAssessed = "not_assessed"
	StatusUnsupported = "unsupported"
)
View Source
const (
	MatrixSchemaVersion = "1"
	MatrixStandard      = "GB/T 42133-2022"

	MatrixPassed        = "passed"
	MatrixFailed        = "failed"
	MatrixWarning       = "warning"
	MatrixManualReview  = "manual_review"
	MatrixNotApplicable = "not_applicable"
	MatrixNotAssessed   = "not_assessed"
	MatrixUnsupported   = "unsupported"
)

Variables

View Source
var ToolVersion = version.Version

ToolVersion 是归档工具的版本。

取自 internal/version,与 --version 输出、查看器关于对话框同源。此前是写死的 "0.0.1",发版时没人跟着动,报告里长期显示着一个早已不存在的版本。

注意归档 verify 从不比对工具版本值(只要求非空),所以发版不会让旧归档失效。

Functions

func BuildManifest

func BuildManifest(ctx context.Context, input string, metadata Metadata, profile string, options Options) (Manifest, Report, error)

BuildManifest 创建技术和档案清单,且不会修改输入文件。

func RenderJSON

func RenderJSON(writer io.Writer, report any, pretty bool) error

func RenderMarkdown

func RenderMarkdown(writer io.Writer, report Report) error

RenderMarkdown 将归档预检报告输出为 Markdown。

func RenderMatrixMarkdown

func RenderMatrixMarkdown(writer io.Writer, matrix MatrixReport) error

RenderMatrixMarkdown 将完整矩阵渲染为便于人工审阅的 Markdown。

func RenderMatrixXLSX

func RenderMatrixXLSX(writer io.Writer, matrix MatrixReport) error

RenderMatrixXLSX 将条文矩阵写入 Office Open XML 工作簿。

func RenderText

func RenderText(writer io.Writer, report Report) error

Types

type Attachment

type Attachment struct {
	DocumentIndex int    `json:"document_index"`
	ID            string `json:"id"`
	Name          string `json:"name"`
	Format        string `json:"format,omitempty"`
	SourcePath    string `json:"source_path"`
	ArchivePath   string `json:"archive_path,omitempty"`
	Size          uint64 `json:"size,omitempty"`
	SHA256        string `json:"sha256,omitempty"`
	Exists        bool   `json:"exists"`
	Copied        bool   `json:"copied"`
	Conversion    string `json:"conversion,omitempty"`
}

type FeatureSummary

type FeatureSummary struct {
	// Actions 是 Actions 容器内 Action 元素的总数,含文档、页面、大纲与批注。
	Actions int `json:"actions,omitempty"`
	// Audio 是 MultiMedia 元素中 Type="Audio" 的数量。
	Audio int `json:"audio,omitempty"`
	// Video 是 MultiMedia 元素中 Type="Video" 的数量。
	Video int `json:"video,omitempty"`
	// Media 是 MultiMedia 元素总数,含图像、音频与视频。
	Media int `json:"media,omitempty"`
	// Encryption 是包内是否存在 Encryptions.xml,为 0 或 1。OFD 用该文件表达
	// 加密,文档 XML 中没有对应元素。
	Encryption int `json:"encryption,omitempty"`
	// Extensions 是 Extension 元素的数量。
	Extensions int `json:"extensions,omitempty"`
}

FeatureSummary 是包内 OFD 要素的清点结果,用于生成检查提示与符合性矩阵的 判断依据,不是合规判定——判定见 pkg/validator 的 profile 规则。

统计只认 OFD 命名空间下的真实元素,口径与 profile 规则对齐,避免同一文件在 两个工具下得出相反结论。

type FileInfo

type FileInfo struct {
	Path      string `json:"path"`
	Size      int64  `json:"size"`
	SHA256    string `json:"sha256"`
	Algorithm string `json:"algorithm"`
}

type Issue

type Issue struct {
	Severity string `json:"severity"`
	Code     string `json:"code"`
	Message  string `json:"message"`
	Hint     string `json:"hint,omitempty"`
	Path     string `json:"path,omitempty"`
}

func VerifyFixity

func VerifyFixity(root string) ([]Issue, error)

VerifyFixity 根据归档根目录中的普通文件校验 fixity/manifest.sha256。

type Manifest

type Manifest struct {
	SchemaVersion string       `json:"schema_version"`
	Tool          ToolInfo     `json:"tool"`
	CreatedAt     time.Time    `json:"created_at"`
	Source        FileInfo     `json:"source"`
	Metadata      Metadata     `json:"metadata"`
	Profile       string       `json:"profile,omitempty"`
	Report        string       `json:"report"`
	Analysis      string       `json:"analysis"`
	Fixity        string       `json:"fixity"`
	Attachments   []Attachment `json:"attachments"`
	Files         []FileInfo   `json:"files"`
}

type MatrixClause

type MatrixClause struct {
	ID            string   `json:"clause"`
	Title         string   `json:"title"`
	Requirement   string   `json:"requirement"`
	Applicability string   `json:"applicability"`
	Status        string   `json:"status"`
	Assessment    string   `json:"assessment"`
	Evidence      []string `json:"evidence,omitempty"`
	Detector      string   `json:"detector,omitempty"`
	ManualReview  bool     `json:"manual_review,omitempty"`
	Limitations   string   `json:"limitations,omitempty"`
}

MatrixClause 表示条文级符合性矩阵中的一行。

type MatrixReport

type MatrixReport struct {
	SchemaVersion string         `json:"schema_version"`
	Standard      string         `json:"standard"`
	Source        string         `json:"source"`
	GeneratedAt   time.Time      `json:"generated_at"`
	Input         FileInfo       `json:"input"`
	OverallStatus string         `json:"overall_status"`
	Summary       MatrixSummary  `json:"summary"`
	Clauses       []MatrixClause `json:"clauses"`
	Preflight     Report         `json:"preflight"`
}

MatrixReport 包含针对指定整理版条款目录生成的完整矩阵。 它是评估辅助工具,不构成法律或认证结论。

func BuildMatrix

func BuildMatrix(ctx context.Context, input string, options Options) (MatrixReport, error)

BuildMatrix 执行技术预检,并评估指定整理版条款目录中的每一条条款。 没有客观检测器的条款保持为 manual_review,而不是 passed。

type MatrixSummary

type MatrixSummary struct {
	Total         int `json:"total"`
	Passed        int `json:"passed"`
	Failed        int `json:"failed"`
	Warnings      int `json:"warnings"`
	ManualReview  int `json:"manual_review"`
	NotApplicable int `json:"not_applicable"`
	NotAssessed   int `json:"not_assessed"`
	Unsupported   int `json:"unsupported"`
}

type Metadata

type Metadata struct {
	ArchiveCode            string `json:"archive_code" yaml:"archive_code"`
	FondsCode              string `json:"fonds_code" yaml:"fonds_code"`
	RetentionPeriod        string `json:"retention_period" yaml:"retention_period"`
	SecurityClassification string `json:"security_classification" yaml:"security_classification"`
	OpenStatus             string `json:"open_status" yaml:"open_status"`
}

func LoadMetadata

func LoadMetadata(filename string) (Metadata, error)

LoadMetadata 从 JSON、YAML 或类 YAML 文件中加载档案描述元数据。

type Options

type Options struct {
	ValidatorOptions  []validator.Option
	AnalyzerOptions   []analyzer.Option
	FailOnWarning     bool
	HashAlgorithm     string
	MaxAttachmentSize int64
	MaxXMLBytes       int64
}

func DefaultOptions

func DefaultOptions() Options

type Profile

type Profile struct {
	Name           string   `json:"name" yaml:"name"`
	RequiredFields []string `json:"required_fields" yaml:"required_fields"`
}

type Report

type Report struct {
	SchemaVersion   string           `json:"schema_version"`
	Tool            ToolInfo         `json:"tool"`
	Input           FileInfo         `json:"input"`
	Status          string           `json:"status"`
	StartedAt       time.Time        `json:"started_at"`
	DurationMS      int64            `json:"duration_ms"`
	Issues          []Issue          `json:"issues"`
	Features        FeatureSummary   `json:"features"`
	Attachments     []Attachment     `json:"attachments"`
	ValidatorReport validator.Report `json:"validator_report"`
	AnalysisReport  analyzer.Report  `json:"analysis_report"`
}

func Check

func Check(ctx context.Context, input string, options Options) (Report, error)

func Prepare

func Prepare(ctx context.Context, input, output string, metadata Metadata, profile string, options Options) (Report, error)

Prepare 复制源 OFD,并写入自包含的归档目录。

func Verify

func Verify(root string) (Report, error)

type ToolInfo

type ToolInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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