Begin work on reading mothballs

This commit is contained in:
Neale Pickett 2018-05-10 02:01:09 +00:00
parent 90146f31ed
commit 9a2ed15316
1 changed files with 52 additions and 0 deletions

52
mothball.go Normal file
View File

@ -0,0 +1,52 @@
package mothball
import (
"archive/zip"
"os"
"time"
)
type Mothball struct {
zf *zipfile.File,
filename string,
mtime time.Time,
}
func Open(filename string) (*Mothball, error) {
var m Mothball
m.filename = filename
err := m.Refresh()
if err != nil {
return err
}
return &m
}
func (m Mothball) Close() (error) {
return m.zf.Close()
}
func (m Mothball) Refresh() (error) {
mtime, err := os.Stat(m.filename)
if err != nil {
return err
}
if mtime == m.mtime {
return nil
}
zf, err := zip.OpenReader(m.filename)
if err != nil {
return err
}
m.zf.Close()
m.zf = zf
m.mtime = mtime
}
func (m Mothball)