diff --git a/cmd/htpacker/packer/packer.go b/cmd/htpacker/packer/packer.go index 6dba182..00cc31e 100644 --- a/cmd/htpacker/packer/packer.go +++ b/cmd/htpacker/packer/packer.go @@ -325,14 +325,11 @@ func (p *packer) packFile(path string, fileToPack FileToPack) { return } - var data []byte - if fi.Size() > 0 { - data, err = unix.Mmap(int(f.Fd()), 0, int(fi.Size()), - unix.PROT_READ, unix.MAP_SHARED) - if err != nil { - p.Abort(fmt.Errorf("mmap %s: %v", fileToPack.Filename, err)) - return - } + data, err := unix.Mmap(int(f.Fd()), 0, int(fi.Size()), + unix.PROT_READ, unix.MAP_SHARED) + if err != nil { + p.Abort(fmt.Errorf("mmap %s: %v", fileToPack.Filename, err)) + return } // prepare initial directory entry diff --git a/cmd/htpacker/yaml.go b/cmd/htpacker/yaml.go index 37e10e1..eb8eaba 100644 --- a/cmd/htpacker/yaml.go +++ b/cmd/htpacker/yaml.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "io" "io/ioutil" "net/http" "os" @@ -126,22 +125,13 @@ func filesFromListR(prefix, arg string, ftp packer.FilesToPack) error { case fi.Mode().IsRegular(): // sniff content type - var ctype string buf := make([]byte, 512) n, err := f.Read(buf) - switch err { - case nil: - buf = buf[:n] - ctype = http.DetectContentType(buf) - - case io.EOF: - // Empty file; this is typically due to things like - // npm webpack producing empty .css files. - ctype = "text/plain; charset=UTF-8" - - default: - return fmt.Errorf("failed to read %s: %v", arg, err) + if err != nil { + return err } + buf = buf[:n] + ctype := http.DetectContentType(buf) // augmented rules for JS / CSS / etc. switch {