Title: ota中有tar.gz压缩包升级方式,请问这个压缩包是如何制作的 · Issue #2 · QuecPython/QFrame · GitHub
Open Graph Title: ota中有tar.gz压缩包升级方式,请问这个压缩包是如何制作的 · Issue #2 · QuecPython/QFrame
X Title: ota中有tar.gz压缩包升级方式,请问这个压缩包是如何制作的 · Issue #2 · QuecPython/QFrame
Description: class FileDecode(object): def __init__(self, zip_file, parent_dir="/fota/usr/"): self.data = b'' self.fp = open(zip_file, "rb") self.fileData = None self.parent_dir = parent_dir self.update_file_list = [] def get_update_files(self): retu...
Open Graph Description: class FileDecode(object): def __init__(self, zip_file, parent_dir="/fota/usr/"): self.data = b'' self.fp = open(zip_file, "rb") self.fileData = None self.parent_dir = parent_dir self.update_file_li...
X Description: class FileDecode(object): def __init__(self, zip_file, parent_dir="/fota/usr/"): self.data = b'' self.fp = open(zip_file, "rb") self.fileData = None self.parent_dir = pa...
Opengraph URL: https://github.com/QuecPython/QFrame/issues/2
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ota中有tar.gz压缩包升级方式,请问这个压缩包是如何制作的","articleBody":"```\nclass FileDecode(object):\n\n def __init__(self, zip_file, parent_dir=\"/fota/usr/\"):\n self.data = b''\n self.fp = open(zip_file, \"rb\")\n self.fileData = None\n self.parent_dir = parent_dir\n self.update_file_list = []\n\n def get_update_files(self):\n return self.update_file_list\n\n def unzip(self):\n \"\"\"缓存到内存中\"\"\"\n self.fp.seek(10)\n self.fileData = uzlib.DecompIO(self.fp, -15, 1)\n\n @classmethod\n def _ascii_trip(cls, data):\n return data.decode('ascii').rstrip('\\0')\n\n @classmethod\n def file_size(cls, data):\n \"\"\"获取真实size数据\"\"\"\n size = cls._ascii_trip(data)\n if not len(size):\n return 0\n return int(size, 8)\n\n @classmethod\n def get_file_name(cls, file_name):\n \"\"\"获取文件名称\"\"\"\n return cls._ascii_trip(file_name)\n\n def get_data(self):\n return self.fileData.read(0x200)\n\n def unpack(self):\n try:\n folder_list = set()\n self.data = self.get_data()\n while True:\n if not self.data:\n break\n size = self.file_size(self.data[124:135])\n file_name = self.get_file_name(self.data[:100])\n full_file_name = self.parent_dir + file_name\n\n if not size:\n if len(full_file_name):\n ql_fs.mkdirs(full_file_name)\n if full_file_name not in folder_list and full_file_name != self.parent_dir:\n folder_list.add(full_file_name)\n else:\n return\n self.data = self.get_data()\n else:\n self.data = self.get_data()\n update_file = open(full_file_name, \"wb+\")\n total_size = size\n while True:\n size -= 0x200\n if size \u003c= 0:\n update_file.write(self.data[:size + 512])\n break\n else:\n update_file.write(self.data)\n self.data = self.get_data()\n self.data = self.get_data()\n update_file.close()\n self.update_file_list.append({\"file_name\": file_name, \"size\": total_size})\n except Exception as e:\n self.fp.close()\n return False\n else:\n self.fp.close()\n return True\n\n\nclass AppFota(object):\n\n def __init__(self):\n self.fota = BaseAppFota.new()\n\n def set_update_flag(self):\n \"\"\"设置升级标志(当且仅当升级文件下载成功后,且设置了升级标志,重启后才会触发升级,否则不升级。)\"\"\"\n self.fota.set_update_flag()\n\n def download(self, url, file_name):\n \"\"\"下载单一升级文件\n\n @url: 待下载文件的url,类型为str。\n @file_name: 本地待升级文件的绝对路径,类型str。\n \"\"\"\n if self.fota.download(url, file_name) == 0:\n return True\n return False\n\n def bulk_download(self, info):\n \"\"\"批量下载升级文件\n\n @info: 批量下载列表,列表的元素均为包含了url和file_name的字典,类型为list\n \"\"\"\n return self.fota.bulk_download(info)\n\n @staticmethod\n def __download_file_from_server(url, path):\n response = request.get(url)\n if response.status_code not in (200, 206):\n return False\n with open(path, 'wb') as f:\n for c in response.content:\n f.write(c)\n\n @staticmethod\n def __decode_file_to_updater_dir(path, updater_dir):\n fd = FileDecode(path, parent_dir=updater_dir)\n ql_fs.mkdirs(updater_dir)\n fd.unzip()\n if fd.unpack():\n for file in fd.update_file_list:\n update_download_stat('', '/usr/' + file['file_name'], file['size'])\n return True\n else:\n return False\n\n def download_tar(self, url, path=\"/usr/temp.tar.gz\"):\n \"\"\"通过压缩文件下载升级。\"\"\"\n self.__download_file_from_server(url, path)\n if self.__decode_file_to_updater_dir(\n path,\n self.fota.app_fota_pkg_mount.fota_dir + '/usr/.updater/usr/'\n ):\n uos.remove(path)\n return True\n else:\n return False\n```\n\n这个解压缩函数,对应的压缩包是如何制作的","author":{"url":"https://github.com/Connor-WangK","@type":"Person","name":"Connor-WangK"},"datePublished":"2025-04-09T03:28:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2/QFrame/issues/2"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04116bb3-2ef6-e494-d0c5-28773ce2b43d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF74:1D772C:216B378:2C1FE9D:696B1071 |
| html-safe-nonce | 1fac33c4197a05df16fa6f323c0682ff7c6e9715c33873e0be2a82e81fbdaa39 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjc0OjFENzcyQzoyMTZCMzc4OjJDMUZFOUQ6Njk2QjEwNzEiLCJ2aXNpdG9yX2lkIjoiMjQ3MTA5MzQxMDk5OTI0Mjg2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5297d094e2e5fa8f8a45edc1f247e6869e0ff73b0cb1816cfbd507958924f40b |
| hovercard-subject-tag | issue:2981432685 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/QuecPython/QFrame/2/issue_layout |
| twitter:image | https://opengraph.githubassets.com/110dfeaa6a2fcf3bd76cc5e345432a84ed460c3d9fa11e220567105e15485cc1/QuecPython/QFrame/issues/2 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/110dfeaa6a2fcf3bd76cc5e345432a84ed460c3d9fa11e220567105e15485cc1/QuecPython/QFrame/issues/2 |
| og:image:alt | class FileDecode(object): def __init__(self, zip_file, parent_dir="/fota/usr/"): self.data = b'' self.fp = open(zip_file, "rb") self.fileData = None self.parent_dir = parent_dir self.update_file_li... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Connor-WangK |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/QuecPython/QFrame git https://github.com/QuecPython/QFrame.git |
| octolytics-dimension-user_id | 76984362 |
| octolytics-dimension-user_login | QuecPython |
| octolytics-dimension-repository_id | 725970472 |
| octolytics-dimension-repository_nwo | QuecPython/QFrame |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 725970472 |
| octolytics-dimension-repository_network_root_nwo | QuecPython/QFrame |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width