From 000691a285bbdd95db386f17605b506750f5ffdf Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:47:17 +0200 Subject: [PATCH] List active blobs helper script --- resources/scripts/decompress_blob.py | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 resources/scripts/decompress_blob.py diff --git a/resources/scripts/decompress_blob.py b/resources/scripts/decompress_blob.py new file mode 100644 index 00000000..3aa6f4f3 --- /dev/null +++ b/resources/scripts/decompress_blob.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Decode a raw Stalwart blob object into its original bytes. + +Stalwart appends a one-byte compression marker to every blob it writes to the +blob store (see BlobStore::put_blob in crates/store/src/dispatch/blob.rs): + + 0x00 (NONE_MARKER) the preceding bytes are the verbatim payload + 0xa1 (LZ4_MARKER) the preceding bytes are an lz4_flex block prefixed with a + little-endian u32 holding the uncompressed size + other a legacy blob stored without a marker; emitted unchanged + +This mirrors the read path, which inspects the last byte, strips the marker and, +for LZ4, decompresses the size-prepended block. + +Reads the object from a file (or stdin with "-") and writes the decoded payload +to stdout (or to a file with -o). +""" + +import argparse +import sys + +NONE_MARKER = 0x00 +LZ4_MARKER = 0xA1 + + +def decode(data): + if not data: + return data + marker = data[-1] + if marker == LZ4_MARKER: + import lz4.block + return lz4.block.decompress(data[:-1]) + if marker == NONE_MARKER: + return data[:-1] + print(f"warning: no known compression marker (last byte 0x{marker:02x}); " + "emitting bytes unchanged", file=sys.stderr) + return data + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("input", help='raw blob file, or "-" to read from stdin') + ap.add_argument("-o", "--output", + help="write the decoded payload here (default: stdout)") + args = ap.parse_args() + + if args.input == "-": + data = sys.stdin.buffer.read() + else: + with open(args.input, "rb") as fh: + data = fh.read() + + out = decode(data) + + if args.output: + with open(args.output, "wb") as fh: + fh.write(out) + else: + sys.stdout.buffer.write(out) + + +if __name__ == "__main__": + main()