From 2bc5d0350ba5bb948aeaf54ecfa59f33eeb6004b Mon Sep 17 00:00:00 2001
From: 554325746@qq.com <554325746@qq.com>
Date: 星期三, 24 七月 2019 14:25:55 +0800
Subject: [PATCH] github.com/long/taskpubsub ==> taskpubsub
---
util/util.go | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/util/util.go b/util/util.go
index d802f4c..96b3edc 100644
--- a/util/util.go
+++ b/util/util.go
@@ -1,5 +1,12 @@
package util
+import(
+ "github.com/pierrec/lz4"
+ "taskpubsub/logger"
+ )
+
+
+
// 1. oldstring element is not in new : abandon(delete)
// 2. new element is not in oldstring : add(add)
func Difference(oldstring []string, newstring []string) map[string]string {
@@ -31,3 +38,31 @@
}
return diff
}
+
+// UnCompress uncompress
+func UnCompress(in []byte) ([]byte, error) {
+ out := make([]byte, 10*len(in))
+ n, err := lz4.UncompressBlock(in, out)
+ if err != nil {
+ logger.Error("uncompress error: ", 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 {
+ logger.Error("compress: ", err)
+ return nil, err
+ }
+ if n >= len(in) {
+ logger.Error("image is not compressible")
+ }
+ out = out[:n] // compressed data
+ return out, nil
+}
--
Gitblit v1.8.0