cligram.utils
- class cligram.utils.Archive(password=None, compression=CompressionType.GZIP, salt=None)[source]
Bases:
objectHigh-performance async archive with encryption and streaming support.
The archive data is held in memory by default for fast operations. Decryption happens only on load, encryption only on export.
Examples
``` # Create archive from directory and save to file async with Archive.from_directory(“my_folder”, password=”secret”) as archive:
await archive.write(“archive.tar.gz”)
# Load archive from file and extract async with await Archive.load(“archive.tar.gz”, password=”secret”) as archive:
await archive.extract(“output_folder”)
# Create archive from bytes data = b”…” # Encrypted archive bytes async with await Archive.from_bytes(data, password=”secret”) as archive:
file_content = await archive.get_file(“document.txt”)
- async extract(output_dir='.')[source]
Extract archive to directory.
- Parameters:
output_dir (
Union[str,Path]) – Directory to extract to- Return type:
Path- Returns:
Path to extracted directory
- get_entry(name)[source]
Get archive entry by name.
- Parameters:
name (
str) – Entry name- Return type:
- Returns:
ArchiveEntry
- list_files()[source]
List all entries in archive.
- Return type:
- Returns:
List of ArchiveEntry objects
- remove_file(name)[source]
Remove file from archive.
- Parameters:
name (
str) – Entry name- Return type:
- Returns:
Removed ArchiveEntry
- class cligram.utils.ArchiveEntry(name, size, file_type, mode, mtime, _content=None, uid=0, gid=0, _uname='', _gname='', pax_headers=<factory>)[source]
Bases:
objectRepresents an entry in the archive.
This is an immutable value object that represents a file, directory, or symlink in an archive. Content hash is computed lazily on first access and cached.
- property content: bytes | None
Get content bytes.
- Returns:
File content or None for non-file entries
- property content_hash: bytes | None
Get SHA-256 hash of the content.
Hash is computed once and cached for performance.
- Returns:
SHA-256 hash bytes or None for non-file entries
-
file_type:
FileType Type of the entry.
- async classmethod from_file(file_path, arcname=None, pax_headers=None)[source]
Create ArchiveEntry from file system path.
- Parameters:
- Return type:
- Returns:
New ArchiveEntry instance
- classmethod from_tar_member(member, content=None)[source]
Create ArchiveEntry from TarInfo.
- Parameters:
- Return type:
- Returns:
New ArchiveEntry instance
- property gname: str
Get group name (lazy computation with fallback).
- Returns:
Group name or empty string if unavailable
- to_dict()[source]
Convert to dictionary representation.
- Return type:
- Returns:
Dictionary with entry metadata (excludes content)
- class cligram.utils.DeviceInfo(platform, architecture, name, version, model, environments)[source]
Bases:
object
- cligram.utils.get_client(config, device, proxy, session)[source]
Create a Telethon TelegramClient from the given configuration.
- Return type:
- cligram.utils.get_device_info(no_cache=False)[source]
Get comprehensive device information across all supported platforms.
- Returns:
Complete device information including platform, architecture, and environment.
- Return type:
- cligram.utils.get_session(config, create=False, device=None)[source]
Load a CustomSession based on the configuration.
- Return type: