Help us shape the future of Go! Take the 2026 Go Developer Survey

zipx

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package zipx writes the ZIP archives lfm ships (EPUB, .docx, .pptx, .xlsx, download and shop ZIPs) the way the strictest readers want them: every entry carries its sizes in its header, no data descriptors, no extra fields, UTF-8 names flagged, one fixed timestamp, so the same input gives the same bytes. EPUB forbids an extra field on its mimetype entry; LibreOffice refuses stored entries followed by a data descriptor.

Index

Constants

View Source
const StampPrefix = "lfm-input:"

StampPrefix starts the zip comment carrying a file's input key; apps never show the comment.

Variables

This section is empty.

Functions

func DosTime

func DosTime(t time.Time) (date, clock uint16)

DosTime is t as a zip entry's MS-DOS date and time.

func Problems

func Problems(data []byte) []string

Problems lists where an archive breaks the rules this package writes by, reading every entry's local header through the central directory: a data descriptor, an extra field, a UTF-8 name without its flag, an EPUB mimetype entry that is compressed. Tests hold every archive lfm builds to it.

func Stamp

func Stamp(tail []byte) string

Stamp is the input key an archive carries in its comment, read from the end of the file; tail may be the whole file or its last bytes.

func WithStamp

func WithStamp(data []byte, key string) []byte

WithStamp sets the comment of an archive without one to the key; a key longer than Stamp reads leaves the archive as it is.

Types

type Packed

type Packed struct {
	Data       []byte // deflated
	CRC        uint32
	Size       uint64 // uncompressed
	Compressed uint64
}

Packed is data compressed once, for entries many archives share, such as a font every document embeds.

func Pack

func Pack(data []byte, level int) Packed

Pack deflates data for Raw.

type Writer

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

Writer appends entries to one archive.

func New

func New(w io.Writer, modified time.Time) *Writer

New starts an archive on w whose entries all carry modified.

func (*Writer) Close

func (w *Writer) Close() error

Close writes the central directory.

func (*Writer) Comment

func (w *Writer) Comment(s string) error

Comment sets the archive's comment.

func (*Writer) Copy

func (w *Writer) Copy(f *zip.File) error

Copy writes an entry of another archive with this archive's header rules, keeping its compressed bytes.

func (*Writer) Deflate

func (w *Writer) Deflate(name string, data []byte) error

Deflate writes a compressed entry.

func (*Writer) Raw

func (w *Writer) Raw(name string, p Packed) error

Raw writes an entry compressed before.

func (*Writer) Store

func (w *Writer) Store(name string, data []byte) error

Store writes an uncompressed entry: for data compressed already (PDF, PNG, JPEG, fonts in a ZIP) and for EPUB's mimetype.

Jump to

Keyboard shortcuts

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