Skip to content

Commit

Permalink
Change NNCE error message encoding to Gzip (#940)
Browse files Browse the repository at this point in the history
The NNCE encodedMessage is now encoded using Gzip, so it can be easily decompressed with standard linux utility.

Signed-off-by: Tomas Psota <[email protected]>
  • Loading branch information
tompsota authored Dec 10, 2021
1 parent 1bab62b commit 16ac90a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/enactmentstatus/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package enactmentstatus

import (
"bytes"
"compress/flate"
"compress/gzip"
b64 "encoding/base64"
"io"
"regexp"
Expand Down Expand Up @@ -137,12 +137,9 @@ func CompressAndEncodeMessage(message string) string {

func compressMessage(message string) (bytes.Buffer, error) {
var buf bytes.Buffer
writer, err := flate.NewWriter(&buf, flate.BestCompression)
if err != nil {
return bytes.Buffer{}, err
}
writer := gzip.NewWriter(&buf)

_, err = writer.Write([]byte(message))
_, err := writer.Write([]byte(message))
if err != nil {
return bytes.Buffer{}, err
}
Expand Down Expand Up @@ -170,7 +167,10 @@ func decodeMessage(encodedMessage string) []byte {

func decompressMessage(data []byte) string {
bytesReader := bytes.NewReader(data)
flateReader := flate.NewReader(bytesReader)
decompressedMessage, _ := io.ReadAll(flateReader)
gzipReader, err := gzip.NewReader(bytesReader)
if err != nil {
return ""
}
decompressedMessage, _ := io.ReadAll(gzipReader)
return string(decompressedMessage)
}

0 comments on commit 16ac90a

Please sign in to comment.