Skip to content

Commit fa5bb71

Browse files
authored
Merge pull request #10 from qmuntal/content-type
Hard-code xml and rels content type as defaults
2 parents 1daf83d + 2f13353 commit fa5bb71

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ language: go
44
go_import_path: github.com/qmuntal/opc
55

66
go:
7-
- 1.12.x
87
- 1.13.x
98
- 1.14.x
9+
- 1.15.x
10+
11+
os:
12+
- linux
13+
- windows
14+
- osx
1015

1116
env:
1217
- GO111MODULE=on

writer.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ type Writer struct {
3838

3939
// NewWriter returns a new Writer writing an OPC file to w.
4040
func NewWriter(w io.Writer) *Writer {
41-
return &Writer{p: newPackage(), w: zip.NewWriter(w), rnd: rand.New(rand.NewSource(42))}
41+
return &Writer{p: &pkg{
42+
parts: make(map[string]*Part, 0),
43+
contentTypes: contentTypes{
44+
defaults: map[string]string{
45+
"xml": "application/xml",
46+
"rels": relationshipContentType,
47+
},
48+
overrides: map[string]string{},
49+
},
50+
}, w: zip.NewWriter(w), rnd: rand.New(rand.NewSource(42))}
4251
}
4352

4453
// Flush flushes any buffered data to the underlying writer.
@@ -78,8 +87,7 @@ func (w *Writer) Close() error {
7887
// This returns a Writer to which the file contents should be written.
7988
// The file's contents must be written to the io.Writer before the next call to Create, CreatePart, or Close.
8089
func (w *Writer) Create(name, contentType string) (io.Writer, error) {
81-
part := &Part{Name: name, ContentType: contentType}
82-
return w.add(part, CompressionNormal)
90+
return w.CreatePart(&Part{Name: name, ContentType: contentType}, CompressionNone)
8391
}
8492

8593
// CreatePart adds a file to the OPC archive using the provided part.
@@ -113,7 +121,7 @@ func (w *Writer) createCoreProperties() error {
113121

114122
func (w *Writer) createContentTypes() error {
115123
// ISO/IEC 29500-2 M3.10
116-
cw, err := w.addToPackage(&Part{Name: contentTypesName, ContentType: "text/xml"}, CompressionNormal)
124+
cw, err := w.addToPackage(&Part{Name: contentTypesName, ContentType: "application/xml"}, CompressionNormal)
117125
if err != nil {
118126
return err
119127
}

writer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func TestWriter_Create(t *testing.T) {
118118
args args
119119
wantErr bool
120120
}{
121+
{"base", NewWriter(&bytes.Buffer{}), args{"/a.xml", "application/xml"}, false},
121122
{"nameErr", NewWriter(&bytes.Buffer{}), args{"a.xml", "a/b"}, true},
122-
{"base", NewWriter(&bytes.Buffer{}), args{"/a.xml", "a/b"}, false},
123123
}
124124
for _, tt := range tests {
125125
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)