You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/01/17 14:00:00 UTC

[camel-k] branch master updated: Fix bug in compression utils

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new 9de63d8  Fix bug in compression utils
9de63d8 is described below

commit 9de63d8aff5a5e55fd3844903526ab5ec3969c97
Author: nferraro <ni...@gmail.com>
AuthorDate: Thu Jan 17 14:38:06 2019 +0100

    Fix bug in compression utils
---
 pkg/gzip/compress.go      |  9 ++++-----
 pkg/gzip/compress_test.go | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/pkg/gzip/compress.go b/pkg/gzip/compress.go
index 8fbe748..ede1ff2 100644
--- a/pkg/gzip/compress.go
+++ b/pkg/gzip/compress.go
@@ -78,17 +78,16 @@ func Uncompress(buffer io.Writer, data []byte) error {
 
 // UncompressBase64 --
 func UncompressBase64(data []byte) ([]byte, error) {
-	var b bytes.Buffer
-
-	err := Uncompress(&b, data)
+	d, err := base64.StdEncoding.DecodeString(string(data))
 	if err != nil {
 		return []byte{}, err
 	}
 
-	d, err := base64.StdEncoding.DecodeString(b.String())
+	var b bytes.Buffer
+	err = Uncompress(&b, d)
 	if err != nil {
 		return []byte{}, err
 	}
 
-	return d, nil
+	return b.Bytes(), nil
 }
diff --git a/pkg/gzip/compress_test.go b/pkg/gzip/compress_test.go
new file mode 100644
index 0000000..e77ae95
--- /dev/null
+++ b/pkg/gzip/compress_test.go
@@ -0,0 +1,32 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package gzip
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestCompression(t *testing.T) {
+	source := "this is a script"
+	compressed, err := CompressBase64([]byte(source))
+	assert.Nil(t, err)
+	uncompressed, err := UncompressBase64(compressed)
+	assert.Nil(t, err)
+	assert.Equal(t, source, string(uncompressed))
+}