mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00

* update license and terms * Fixes * Create ACKNOWLEDGEMENTS.md * Update ACKNOWLEDGEMENTS.md * Revert go.mod changes and remove go1.11 tests
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
|
//
|
|
// Use of this software package and source code is governed by the terms of the
|
|
// UniDoc End User License Agreement (EULA) that is available at:
|
|
// https://unidoc.io/eula/
|
|
// A trial license code for evaluation can be obtained at https://unidoc.io.
|
|
|
|
package common
|
|
|
|
import (
|
|
"archive/zip"
|
|
"fmt"
|
|
"image"
|
|
|
|
"github.com/unidoc/unioffice/zippkg"
|
|
)
|
|
|
|
// DocBase is the type embedded in in the Document/Workbook/Presentation types
|
|
// that contains members common to all.
|
|
type DocBase struct {
|
|
ContentTypes ContentTypes
|
|
AppProperties AppProperties
|
|
Rels Relationships
|
|
CoreProperties CoreProperties
|
|
CustomProperties CustomProperties
|
|
Thumbnail image.Image // thumbnail preview of the document
|
|
|
|
Images []ImageRef
|
|
ExtraFiles []ExtraFile
|
|
TmpPath string // path where temporary files are stored when opening documents
|
|
|
|
}
|
|
|
|
// AddExtraFileFromZip is used when reading an unsupported file from an OOXML
|
|
// file. This ensures that unsupported file content will at least round-trip
|
|
// correctly.
|
|
func (d *DocBase) AddExtraFileFromZip(f *zip.File) error {
|
|
path, err := zippkg.ExtractToDiskTmp(f, d.TmpPath)
|
|
if err != nil {
|
|
return fmt.Errorf("error extracting unsupported file: %s", err)
|
|
}
|
|
d.ExtraFiles = append(d.ExtraFiles, ExtraFile{
|
|
ZipPath: f.Name,
|
|
DiskPath: path,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// WriteExtraFiles writes the extra files to the zip package.
|
|
func (d *DocBase) WriteExtraFiles(z *zip.Writer) error {
|
|
for _, ef := range d.ExtraFiles {
|
|
if err := zippkg.AddFileFromDisk(z, ef.ZipPath, ef.DiskPath); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ExtraFile is an unsupported file type extracted from, or to be written to a
|
|
// zip package
|
|
type ExtraFile struct {
|
|
ZipPath string
|
|
DiskPath string
|
|
}
|