diff options
| author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-05-07 16:12:51 +0800 |
|---|---|---|
| committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-05-07 16:12:51 +0800 |
| commit | 38ad20efc11c1872c4e62a12617f0300c138b867 (patch) | |
| tree | 7190083ed4fa8ddaa1ec3b9ecb260423451f3164 /lib.go | |
| parent | bc451a78de32ccde2a4f6d0851ea6e41e45408f1 (diff) | |
save bytes on memory instead of string
Diffstat (limited to 'lib.go')
| -rw-r--r-- | lib.go | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -12,8 +12,8 @@ import ( // ReadZipReader can be used to read an XLSX in memory without touching the // filesystem. -func ReadZipReader(r *zip.Reader) (map[string]string, int, error) { - fileList := make(map[string]string) +func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) { + fileList := make(map[string][]byte) worksheets := 0 for _, v := range r.File { fileList[v.Name] = readFile(v) @@ -27,21 +27,24 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) { } // readXML provides function to read XML content as string. -func (f *File) readXML(name string) string { +func (f *File) readXML(name string) []byte { if content, ok := f.XLSX[name]; ok { return content } - return "" + return []byte{} } // saveFileList provides function to update given file content in file list of // XLSX. -func (f *File) saveFileList(name, content string) { - f.XLSX[name] = XMLHeader + content +func (f *File) saveFileList(name string, content []byte) { + newContent := make([]byte, 0, len(XMLHeader)+len(content)) + newContent = append(newContent, []byte(XMLHeader)...) + newContent = append(newContent, content...) + f.XLSX[name] = newContent } // Read file content as string in a archive file. -func readFile(file *zip.File) string { +func readFile(file *zip.File) []byte { rc, err := file.Open() if err != nil { log.Fatal(err) @@ -49,7 +52,7 @@ func readFile(file *zip.File) string { buff := bytes.NewBuffer(nil) io.Copy(buff, rc) rc.Close() - return string(buff.Bytes()) + return buff.Bytes() } // ToAlphaString provides function to convert integer to Excel sheet column |
