netx/netx_api/config_sync_codec.py
oliver 0eead0e662 Add industrial config sync separate from collection tasks.
Periodic vendor-aware CLI sync stores zlib snapshots in Postgres with dashboard, retry, and config viewer under Network Management.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 10:25:36 +08:00

20 lines
587 B
Python

"""zlib + sha256 helpers for config blobs."""
from __future__ import annotations
import hashlib
import zlib
def compress_text(text: str) -> tuple[bytes, str, int, int]:
"""Return (zlib_bytes, sha256_hex, plain_size, zlib_size)."""
raw = str(text or "").encode("utf-8", errors="replace")
digest = hashlib.sha256(raw).hexdigest()
blob = zlib.compress(raw, level=6)
return blob, digest, len(raw), len(blob)
def decompress_text(blob: bytes | None) -> str:
if not blob:
return ""
return zlib.decompress(bytes(blob)).decode("utf-8", errors="replace")