From fdcec3a4ead5a9f264a6853dc1fa91d2e9fc2354 Mon Sep 17 00:00:00 2001 From: Neil Skinner Date: Wed, 3 Jun 2020 12:46:06 -0400 Subject: [PATCH] Apply hepa filters before gzip'ing content - markbates/pkger#26 --- pkging/embed/embed.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkging/embed/embed.go b/pkging/embed/embed.go index 29dfdf5..5eaf307 100644 --- a/pkging/embed/embed.go +++ b/pkging/embed/embed.go @@ -31,6 +31,15 @@ func Decode(src []byte) ([]byte, error) { } func Encode(b []byte) ([]byte, error) { + hep := hepa.New() + hep = hepa.With(hep, filters.Home()) + hep = hepa.With(hep, filters.Golang()) + + b, err := hep.Filter(b) + if err != nil { + return nil, err + } + bb := &bytes.Buffer{} gz := gzip.NewWriter(bb) @@ -46,16 +55,7 @@ func Encode(b []byte) ([]byte, error) { return nil, err } - hep := hepa.New() - hep = hepa.With(hep, filters.Home()) - hep = hepa.With(hep, filters.Golang()) - - b, err := hep.Filter(bb.Bytes()) - if err != nil { - return nil, err - } - - s := hex.EncodeToString(b) + s := hex.EncodeToString(bb.Bytes()) return []byte(s), nil }