-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstream_reader.go
45 lines (37 loc) · 906 Bytes
/
stream_reader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ooxml
import (
"archive/zip"
"encoding/xml"
"io"
)
//StreamFileReader is stream reader for *zip.File
type StreamFileReader struct {
*xml.Decoder
source *zip.File
reader io.ReadCloser
}
var _ io.Closer = (*StreamFileReader)(nil)
//NewStreamFileReader returns a StreamFileReader for *zip.File f
func NewStreamFileReader(f *zip.File) (*StreamFileReader, error) {
reader, err := f.Open()
if err != nil {
return nil, err
}
return &StreamFileReader{
xml.NewDecoder(reader),
f,
reader,
}, nil
}
//Close closes previously opened file for reading
func (s *StreamFileReader) Close() error {
if s.reader != nil {
var reader io.ReadCloser
reader, s.reader = s.reader, nil
return reader.Close()
}
return nil
}