zippkg

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const XMLHeader = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` + "\n"

XMLHeader is a header that MarshalXML uses to prefix the XML files it creates.

Variables

This section is empty.

Functions

func AddFileFromDisk

func AddFileFromDisk(z *zip.Writer, zipPath, diskPath string) error

AddFileFromDisk reads a file from disk and adds it at a given path to a zip file.

func Decode

func Decode(f *zip.File, dest interface{}) error

Decode unmarshals the content of a *zip.File as XML to a given destination.

func ExtractToDiskTmp

func ExtractToDiskTmp(f *zip.File, path string) (string, error)

ExtractToDiskTmp extracts a zip file to a temporary file in a given path, returning the name of the file.

func MarshalXML

func MarshalXML(z *zip.Writer, filename string, v interface{}) error

MarshalXML creates a file inside of a zip and marshals an object as xml, prefixing it with a standard XML header.

func MarshalXMLByType added in v0.2.0

func MarshalXMLByType(z *zip.Writer, dt gooxml.DocType, typ string, v interface{}) error

func MarshalXMLByTypeIndex added in v0.2.0

func MarshalXMLByTypeIndex(z *zip.Writer, dt gooxml.DocType, typ string, idx int, v interface{}) error

func RelationsPathFor

func RelationsPathFor(path string) string

RelationsPathFor returns the relations path for a given filename.

Types

type DecodeMap added in v0.2.0

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

DecodeMap is used to walk a tree of relationships, decoding files and passing control back to the document.

func (*DecodeMap) AddTarget added in v0.2.0

func (d *DecodeMap) AddTarget(filePath string, ifc interface{}, sourceFileType string, idx uint32) bool

AddTarget allows documents to register decode targets. Path is a path that will be found in the zip file and ifc is an XML element that the file will be unmarshaled to. filePath is the absolute path to the target, ifc is the object to decode into, sourceFileType is the type of file that the reference was discovered in, and index is the index of the source file type.

func (*DecodeMap) Decode added in v0.2.0

func (d *DecodeMap) Decode(files []*zip.File) error

Decode loops decoding targets registered with AddTarget and calling th

func (*DecodeMap) IndexFor added in v0.6.0

func (d *DecodeMap) IndexFor(path string) int

func (*DecodeMap) RecordIndex added in v0.6.0

func (d *DecodeMap) RecordIndex(path string, idx int)

func (*DecodeMap) SetOnNewRelationshipFunc added in v0.2.0

func (d *DecodeMap) SetOnNewRelationshipFunc(fn OnNewRelationshipFunc)

SetOnNewRelationshipFunc sets the function to be called when a new relationship has been discovered.

type OnNewRelationshipFunc added in v0.2.0

type OnNewRelationshipFunc func(decMap *DecodeMap, target, typ string, files []*zip.File, rel *relationships.Relationship, src Target) error

OnNewRelationshipFunc is called when a new relationship has been discovered.

target is a resolved path that takes into account the location of the relationships file source and should be the path in the zip file.

files are passed so non-XML files that can't be handled by AddTarget can be decoded directly (e.g. images)

rel is the actual relationship so its target can be modified if the source target doesn't match where gooxml will write the file (e.g. read in 'xl/worksheets/MyWorksheet.xml' and we'll write out 'xl/worksheets/sheet1.xml')

type SelfClosingWriter

type SelfClosingWriter struct {
	W io.Writer
}

SelfClosingWriter wraps a writer and replaces XML tags of the type <foo></foo> with <foo/>

func (SelfClosingWriter) Write

func (s SelfClosingWriter) Write(b []byte) (int, error)

type Target added in v0.2.0

type Target struct {
	Path  string
	Typ   string
	Ifc   interface{}
	Index uint32
}

Jump to

Keyboard shortcuts

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