Commit 2c93be2a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use io.Copy for reading zip.

parent 2e2e959a
...@@ -2,7 +2,9 @@ package zipfs ...@@ -2,7 +2,9 @@ package zipfs
import ( import (
"archive/zip" "archive/zip"
"bytes"
"fmt" "fmt"
"io"
"os" "os"
"strings" "strings"
"path/filepath" "path/filepath"
...@@ -25,25 +27,18 @@ func (me *ZipFile) Stat() *os.FileInfo { ...@@ -25,25 +27,18 @@ func (me *ZipFile) Stat() *os.FileInfo {
} }
func (me *ZipFile) Data() []byte { func (me *ZipFile) Data() []byte {
data := make([]byte, me.UncompressedSize)
zf := (*me) zf := (*me)
rc, err := zf.Open() rc, err := zf.Open()
if err != nil { if err != nil {
panic("zip open") panic(err)
} }
dest := bytes.NewBuffer(make([]byte, 0, me.UncompressedSize))
start := 0
for { _, err = io.Copyn(dest, rc, int64(me.UncompressedSize))
n, err := rc.Read(data[start:]) if err != nil {
start += n panic(err)
if err == os.EOF {
break
}
if err != nil && err != os.EOF {
panic(fmt.Sprintf("read err: %v, n %v, sz %v", err, n, len(data)))
}
} }
return data return dest.Bytes()
} }
func zipFilesToTree(files []*zip.File) *MemTree { func zipFilesToTree(files []*zip.File) *MemTree {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment