summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/binary/unpack.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-01-31 00:27:37 +0100
committerWim <wim@42.be>2022-03-20 14:57:48 +0100
commite3cafeaf9292f67459ff1d186f68283bfaedf2ae (patch)
treeb69c39620aa91dba695b3b935c6651c0fb37ce75 /vendor/go.mau.fi/whatsmeow/binary/unpack.go
parente7b193788a56ee7cdb02a87a9db0ad6724ef66d5 (diff)
downloadmatterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.gz
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.bz2
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.zip
Add dependencies/vendor (whatsapp)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/binary/unpack.go')
-rw-r--r--vendor/go.mau.fi/whatsmeow/binary/unpack.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/binary/unpack.go b/vendor/go.mau.fi/whatsmeow/binary/unpack.go
new file mode 100644
index 00000000..a4557c57
--- /dev/null
+++ b/vendor/go.mau.fi/whatsmeow/binary/unpack.go
@@ -0,0 +1,31 @@
+// Copyright (c) 2021 Tulir Asokan
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+package binary
+
+import (
+ "bytes"
+ "compress/zlib"
+ "fmt"
+ "io"
+)
+
+// Unpack unpacks the given decrypted data from the WhatsApp web API.
+//
+// It checks the first byte to decide whether to uncompress the data with zlib or just return as-is
+// (without the first byte). There's currently no corresponding Pack function because Marshal
+// already returns the data with a leading zero (i.e. not compressed).
+func Unpack(data []byte) ([]byte, error) {
+ dataType, data := data[0], data[1:]
+ if 2&dataType > 0 {
+ if decompressor, err := zlib.NewReader(bytes.NewReader(data)); err != nil {
+ return nil, fmt.Errorf("failed to create zlib reader: %w", err)
+ } else if data, err = io.ReadAll(decompressor); err != nil {
+ return nil, err
+ }
+ }
+ return data, nil
+}