From 07385392f21fab8562c1ea551c5672c772dce20d Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 26 七月 2019 21:07:07 +0800
Subject: [PATCH] sdkmessage uncompress

---
 extend/util/util.go |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/extend/util/util.go b/extend/util/util.go
index 5d51602..8f7883c 100644
--- a/extend/util/util.go
+++ b/extend/util/util.go
@@ -7,6 +7,7 @@
 	"errors"
 	"github.com/gin-gonic/gin"
 	"github.com/golang/glog"
+	"github.com/pierrec/lz4"
 	"gocv.io/x/gocv"
 	"image"
 	"net"
@@ -197,4 +198,32 @@
 	}
 	f, _ := strconv.ParseFloat(fmt.Sprintf("%2.2f", compareScore), 32)
 	return float32(f)
-}
\ No newline at end of file
+}
+
+// UnCompress uncompress
+func UnCompress(in []byte) ([]byte, error) {
+	out := make([]byte, 10*len(in))
+	n, err := lz4.UncompressBlock(in, out)
+	if err != nil {
+		fmt.Println(err)
+		return nil, err
+	}
+	out = out[:n] // uncompressed data
+	return out, nil
+}
+
+// Compress compress
+func Compress(in []byte) ([]byte, error) {
+	out := make([]byte, len(in))
+	ht := make([]int, 64<<10) // buffer for the compression table
+	n, err := lz4.CompressBlock(in, out, ht)
+	if err != nil {
+		fmt.Println(err)
+		return nil, err
+	}
+	if n >= len(in) {
+		fmt.Println("image is not compressible")
+	}
+	out = out[:n] // compressed data
+	return out, nil
+}

--
Gitblit v1.8.0