Skip to content

Commit

Permalink
Add ZipReader field to get original order of ZIP entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Apr 6, 2018
1 parent 7f277a0 commit c79667c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion zipreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type zipReaderFileSubEntry struct {
type ZipReader struct {
File map[string]*ZipReaderFile

// Files in the order they were found in the zip. May contain the same ZipReaderFile
// multiple times in case of broken/crafted ZIPs
FilesOrdered []*ZipReaderFile

zipFile *os.File
}

Expand Down Expand Up @@ -156,12 +160,14 @@ func OpenZip(zippath string) (zr *ZipReader, err error) {
for _, zf := range zipinfo.File {
cl := path.Clean(zf.Name)
if zr.File[cl] == nil {
zr.File[cl] = &ZipReaderFile{
zf := &ZipReaderFile{
Name: cl,
IsDir: zf.FileInfo().IsDir(),
zipFile: f,
zipEntry: zf,
}
zr.File[cl] = zf
zr.FilesOrdered = append(zr.FilesOrdered, zf)
}
}
return
Expand Down Expand Up @@ -209,6 +215,7 @@ func OpenZip(zippath string) (zr *ZipReader, err error) {
}
zr.File[fileName] = zrf
}
zr.FilesOrdered = append(zr.FilesOrdered, zrf)

zrf.entries = append([]zipReaderFileSubEntry{zipReaderFileSubEntry{
offset: fileOffset,
Expand Down

0 comments on commit c79667c

Please sign in to comment.