summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/binary/unpack.go
diff options
context:
space:
mode:
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
+}