Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qmuntal/opc
Go implementation of the Open Packaging Conventions (OPC)
https://github.com/qmuntal/opc
files go golang opc xml
Last synced: about 2 months ago
JSON representation
Go implementation of the Open Packaging Conventions (OPC)
- Host: GitHub
- URL: https://github.com/qmuntal/opc
- Owner: qmuntal
- License: bsd-2-clause
- Created: 2018-11-06T14:49:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-01T11:51:55.000Z (about 1 year ago)
- Last Synced: 2024-07-31T20:51:28.291Z (5 months ago)
- Topics: files, go, golang, opc, xml
- Language: Go
- Homepage:
- Size: 2.24 MB
- Stars: 75
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go - opc - Load Open Packaging Conventions (OPC) files for Go. (File Handling / Search and Analytic Databases)
- awesome-go-extra - opc - 11-06T14:49:06Z|2021-03-01T20:00:33Z| (File Handling / Advanced Console UIs)
README
# opc
[![PkgGoDev](https://pkg.go.dev/badge/github.com/qmuntal/opc)](https://pkg.go.dev/github.com/qmuntal/opc)
[![Build Status](https://github.com/qmuntal/opc/actions/workflows/test.yml/badge.svg)](https://github.com/qmuntal/opc/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/qmuntal/opc)](https://goreportcard.com/report/github.com/qmuntal/opc)
[![codecov](https://coveralls.io/repos/github/qmuntal/opc/badge.svg)](https://coveralls.io/github/qmuntal/opc?branch=master)
[![codeclimate](https://codeclimate.com/github/qmuntal/opc/badges/gpa.svg)](https://codeclimate.com/github/qmuntal/opc)
[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)Package opc implements the ISO/IEC 29500-2, also known as the [Open Packaging Convention](https://en.wikipedia.org/wiki/Open_Packaging_Conventions).
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
- [x] Package reader and writer
- [x] Package core properties and relationships
- [x] Part relationships
- [x] ZIP mapping
- [x] Package, relationships and parts validation against specs
- [ ] Part interleaved pieces
- [ ] Digital signatures## Examples
### Write
```go
// 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
```go
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()
}
```