diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/go.mau.fi/whatsmeow/binary/unpack.go | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/go.mau.fi/whatsmeow/binary/unpack.go')
| -rw-r--r-- | teleirc/matterbridge/vendor/go.mau.fi/whatsmeow/binary/unpack.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/go.mau.fi/whatsmeow/binary/unpack.go b/teleirc/matterbridge/vendor/go.mau.fi/whatsmeow/binary/unpack.go new file mode 100644 index 0000000..a4557c5 --- /dev/null +++ b/teleirc/matterbridge/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 +} |
