boot.img: more compression options

This commit is contained in:
Mikaël Cluseau 2018-11-15 18:07:10 +11:00
parent 12ade36fd1
commit 7f331cb9c6
3 changed files with 29 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"archive/tar"
"compress/gzip"
"io"
"io/ioutil"
"log"
@ -40,11 +41,29 @@ func buildBootImg(out io.Writer, ctx *renderContext) (err error) {
// send the result
bootImg.Seek(0, os.SEEK_SET)
io.Copy(out, bootImg)
return
}
func buildBootImgLZ4(out io.Writer, ctx *renderContext) (err error) {
lz4Out := lz4.NewWriter(out)
io.Copy(lz4Out, bootImg)
lz4Out.Close()
if err = buildBootImg(lz4Out, ctx); err != nil {
return
}
lz4Out.Close()
return
}
func buildBootImgGZ(out io.Writer, ctx *renderContext) (err error) {
gzOut := gzip.NewWriter(out)
if err = buildBootImg(gzOut, ctx); err != nil {
return
}
gzOut.Close()
return
}

View File

@ -165,9 +165,15 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *clust
case "boot.tar":
err = renderCtx(w, r, ctx, "boot.tar", buildBootTar)
case "boot.img.lz4":
case "boot.img":
err = renderCtx(w, r, ctx, what, buildBootImg)
case "boot.img.gz":
err = renderCtx(w, r, ctx, what, buildBootImgGZ)
case "boot.img.lz4":
err = renderCtx(w, r, ctx, what, buildBootImgLZ4)
case "config":
err = renderConfig(w, r, ctx)

View File

@ -46,6 +46,7 @@ func renderStaticPods(w http.ResponseWriter, r *http.Request, ctx *renderContext
return nil
}
// TODO move somewhere logical
func renderCtx(w http.ResponseWriter, r *http.Request, ctx *renderContext, what string,
create func(out io.Writer, ctx *renderContext) error) error {
log.Printf("sending %s for %q", what, ctx.Host.Name)