github.com/matrixorigin/matrixone@v1.2.0/pkg/compress/compress.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package compress 16 17 import ( 18 "github.com/pierrec/lz4/v4" 19 ) 20 21 var Algorithms map[string]int = map[string]int{ 22 "lz4": Lz4, 23 "none": None, 24 } 25 26 func Compress(src, dst []byte, typ int) ([]byte, error) { 27 switch typ { 28 case Lz4: 29 n, err := lz4.CompressBlock(src, dst, nil) 30 if err != nil { 31 return nil, err 32 } 33 return dst[:n], nil 34 } 35 return nil, nil 36 } 37 38 func Decompress(src, dst []byte, typ int) ([]byte, error) { 39 switch typ { 40 case Lz4: 41 n, err := lz4.UncompressBlock(src, dst) 42 if err != nil { 43 return nil, err 44 } 45 return dst[:n], nil 46 } 47 return nil, nil 48 }