| | |
| | | import os |
| | | import json |
| | | import re |
| | | import asyncio |
| | | |
| | | |
| | | def get_bit_mask(start, end): |
| | |
| | | |
| | | return md5_digest |
| | | |
| | | |
| | | def generate_bytes_md5(input_bytes): |
| | | # 创建一个 md5 哈希对象 |
| | | md5_hash = hashlib.md5() |
| | |
| | | |
| | | return md5_digest |
| | | |
| | | |
| | | async def get_md5_async(file: bytes): |
| | | md5 = await asyncio.to_thread(generate_bytes_md5, file) |
| | | return md5 |
| | | |
| | | |
| | | async def save_to_file_async(data: bytes, file_path: str): |
| | | await asyncio.to_thread(save_bytes_to_file, data, file_path) |
| | | |
| | | |
| | | def file_exists(cache_file: str): |
| | | return os.path.exists(cache_file) |
| | | |
| | | |
| | | def read_from_file(cache_file: str) -> str: |
| | | with open(cache_file, 'r', encoding='utf-8') as f: |
| | | def read_from_file(file: str) -> str: |
| | | with open(file, 'r', encoding='utf-8') as f: |
| | | text = f.read() |
| | | return text |
| | | |
| | | |
| | | def save_to_file(text, cache_file): |
| | | with open(cache_file, 'w', encoding='utf-8') as f: |
| | | def save_text_to_file(text: str, file: str): |
| | | with open(file, 'w', encoding='utf-8') as f: |
| | | f.write(text) |
| | | |
| | | |
| | | def save_bytes_to_file(bytes_data: bytes, file: str): |
| | | with open(file, 'wb') as f: |
| | | f.write(bytes_data) |
| | | |
| | | |
| | | def replace_tpl_paras(tpl_text: str, data: dict): |
| | | for key, val in data.items(): |
| | | if not isinstance(val, str): |