Skip to content
Go implementation of the Open Packaging Conventions (OPC)
Go
Branch: master
Clone or download
Latest commit cde29c1 Oct 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata add tests for readers Feb 5, 2019
.gitignore Initial commit Nov 6, 2018
.travis.yml support go1.12 and go 1.13 Oct 18, 2019
LICENSE Initial commit Nov 6, 2018
README.md migrate to travis-ci.com Oct 18, 2019
errors.go add context to io errors Oct 18, 2019
errors_test.go improve Error message Oct 18, 2019
example_test.go add tests for readers Feb 5, 2019
go.mod add context to io errors Oct 18, 2019
go.sum as OpenReader boilerplate and example Feb 5, 2019
package.go use %v instead of %w Oct 18, 2019
package_test.go rename gopc to opc Feb 5, 2019
part.go use %v instead of %w Oct 18, 2019
part_test.go add ResolveRelationship Apr 9, 2019
reader.go
reader_test.go export decompress method Apr 8, 2019
relationship.go use %v instead of %w Oct 18, 2019
relationship_test.go rename gopc to opc Feb 5, 2019
writer.go use %v instead of %w Oct 18, 2019
writer_test.go improve random number generator for writer Feb 7, 2019
zip_reader.go export decompress method Apr 8, 2019

README.md

opc

Documentation Build Status Go Report Card codecov codeclimate License Mentioned in Awesome Go

Package opc implements the ISO/IEC 29500-2, also known as the Open Packaging Convention.

The Open Packaging specification describes an abstract model and physical format conventions for the use of XML, Unicode, ZIP, and other openly available technologies and specifications to organize the content and resources of a document within a package.

The OPC is the foundation technology for many new file formats: .docx, .pptx, .xlsx, .3mf, .dwfx, ...

Features

  • Package reader and writer
  • Package core properties and relationships
  • Part relationships
  • ZIP mapping
  • Package, relationships and parts validation against specs
  • Part interleaved pieces
  • Digital signatures

Examples

Write

// Create a file to write our archive to.
f, _ := os.Create("example.xlsx")

// Create a new OPC archive.
w := opc.NewWriter(f)

// Create a new OPC part.
name := opc.NormalizePartName("docs\\readme.txt")
part, _ := w.Create(name, "text/plain")

// Write content to the part.
part.Write([]byte("This archive contains some text files."))

// Make sure to check the error on Close.
w.Close()

Read

r, _ := opc.OpenReader("testdata/test.xlsx")
defer r.Close()

// Iterate through the files in the archive,
// printing some of their contents.
for _, f := range r.Files {
  fmt.Printf("Contents of %s with type %s :\n", f.Name, f.ContentType)
  rc, _ := f.Open()
  io.CopyN(os.Stdout, rc, 68)
  rc.Close()
  fmt.Println()
}
You can’t perform that action at this time.