{"id":16217269,"url":"https://github.com/synodriver/pybase16384","last_synced_at":"2025-03-19T10:30:43.587Z","repository":{"id":43100738,"uuid":"470941287","full_name":"synodriver/pybase16384","owner":"synodriver","description":"Encode binary files to printable utf16be.","archived":false,"fork":false,"pushed_at":"2024-04-07T13:33:52.000Z","size":1111,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"v0.3","last_synced_at":"2024-10-11T11:26:09.182Z","etag":null,"topics":["base16384","cffi","cython","pypy","pypy3","python","python-3","utf16be"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synodriver.png","metadata":{"files":{"readme":"README.markdown","changelog":"changename.py","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-17T10:12:06.000Z","updated_at":"2023-01-13T11:55:43.000Z","dependencies_parsed_at":"2024-02-03T18:31:26.157Z","dependency_job_id":"1f2dc4ac-3189-4bd9-aa26-7809c68c3a28","html_url":"https://github.com/synodriver/pybase16384","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":0.04081632653061229,"last_synced_commit":"cf511103102d96c303e4ac4542ffe5585b797876"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synodriver%2Fpybase16384","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synodriver%2Fpybase16384/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synodriver%2Fpybase16384/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synodriver%2Fpybase16384/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synodriver","download_url":"https://codeload.github.com/synodriver/pybase16384/tar.gz/refs/heads/v0.3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982182,"owners_count":20378605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base16384","cffi","cython","pypy","pypy3","python","python-3","utf16be"],"created_at":"2024-10-10T11:26:21.746Z","updated_at":"2025-03-19T10:30:43.182Z","avatar_url":"https://github.com/synodriver.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\u003ci\u003e✨ pybase16384 ✨ \u003c/i\u003e\u003c/h1\u003e\n\n\u003ch3 align=\"center\"\u003eThe python binding for \u003ca href=\"https://github.com/fumiama/base16384\"\u003ebase16384\u003c/a\u003e \u003c/h3\u003e\n\n\u003ch3 align=\"center\"\u003e\u003ci\u003e一种神奇的编码 \u003c/i\u003e\u003c/h3\u003e\n\n[![pypi](https://img.shields.io/pypi/v/pybase16384.svg)](https://pypi.org/project/pybase16384/)\n![python](https://img.shields.io/pypi/pyversions/pybase16384)\n![implementation](https://img.shields.io/pypi/implementation/pybase16384)\n![wheel](https://img.shields.io/pypi/wheel/pybase16384)\n![license](https://img.shields.io/github/license/synodriver/pybase16384.svg)\n![action](https://img.shields.io/github/workflow/status/synodriver/pybase16384/build%20wheel)\n\n\n### 使用\n\n- 编码/解码文本\n```python\n\u003e\u003e\u003e import pybase16384 as pybs\n\u003e\u003e\u003e pybs.encode_string('hello!!')\n'栙擆羼漡'\n\u003e\u003e\u003e pybs.decode_string('栙擆羼漡')\n'hello!!'\n```\n\n- 编码文件\n\n```python\nfrom io import BytesIO\n\nimport pybase16384 as pybs\n\nwith open(\"input.pcm\", \"rb\") as f:\n    data = f.read()\nfor i in range(1):\n    pybs.encode_file(BytesIO(data), open(\"output2.pcm\", 'wb'), True)\n```\n- 解码文件\n\n```python\nfrom io import BytesIO\n\nimport pybase16384 as pybs\n\nwith open(\"output2.pcm\", \"rb\") as f:\n    data = f.read()\nfor i in range(1):\n    pybs.decode_file(BytesIO(data), open(\"input2.pcm\", 'wb'))\n```\n\n### 公开函数\n```python\nfrom typing import IO\n\ndef encode_len(dlen: int) -\u003e int: ...\n\ndef decode_len(dlen: int, offset: int) -\u003e int: ...\n\nENCBUFSZ: int\nDECBUFSZ: int\nFLAG_NOHEADER: int\nFLAG_SUM_CHECK_ON_REMAIN: int\nFLAG_DO_SUM_CHECK_FORCELY: int\n\ndef is_64bits() -\u003e bool: ...\n\ndef encode_file(input: IO, output: IO, write_head: bool = ..., buf_rate: int = ...): ...\n\ndef encode_file_safe(input: IO, output: IO, write_head: bool = ..., buf_rate: int = ...): ...\n\ndef decode_file(input: IO, output: IO, buf_rate: int = ...): ...\n\ndef decode_file_safe(input: IO, output: IO, buf_rate: int = ...): ...\n\ndef ensure_bytes(inp) -\u003e bytes: ...\n\ndef encode_local_file(inp, out) -\u003e None: ...\n\ndef decode_local_file(inp, out) -\u003e None: ...\n\ndef encode_fd(inp: int, out: int) -\u003e None: ...\n\ndef decode_fd(inp: int, out: int) -\u003e None: ...\n\ndef encode_local_file_detailed(inp, out, flag: int) -\u003e None: ...\n\ndef decode_local_file_detailed(inp, out, flag: int) -\u003e None: ...\n\ndef encode_fd_detailed(inp: int, out: int, flag: int) -\u003e None: ...\n\ndef decode_fd_detailed(inp: int, out: int, flag: int) -\u003e None: ...\n\ndef encode(data: bytes) -\u003e bytes: ...\n\ndef encode_safe(data: bytes) -\u003e bytes: ...\n\ndef decode(data: bytes) -\u003e bytes: ...\n\ndef decode_safe(data: bytes) -\u003e bytes: ...\n\ndef encode_from_string(data: str, write_head: bool = ...) -\u003e bytes: ...\n\ndef encode_from_string_safe(data: str, write_head: bool = ...) -\u003e bytes: ...\n\ndef encode_to_string(data: bytes) -\u003e str: ...\n\ndef encode_to_string_safe(data: bytes) -\u003e str: ...\n\ndef encode_string(data: str) -\u003e str: ...\n\ndef encode_string_safe(data: str) -\u003e str: ...\n\ndef decode_from_bytes(data: bytes) -\u003e str: ...\n\ndef decode_from_bytes_safe(data: bytes) -\u003e str: ...\n\ndef decode_from_string(data: str) -\u003e bytes: ...\n\ndef decode_from_string_safe(data: str) -\u003e bytes: ...\n\ndef decode_string(data: str) -\u003e str: ...\n\ndef decode_string_safe(data: str) -\u003e str: ...\n\ndef encode_stream_detailed(inp, out, flag: int): ...\n\ndef decode_stream_detailed(inp, out, flag: int): ...\n```\n- write_head将显式指明编码出的文本格式(utf16be)，以便文本编辑器(如记事本)能够正确渲染，一般在写入文件时使用。\n\n- buf_rate指定读取文件的策略。当它为n时，则表示一次读取7n或者8n个字节。如果读到的字节长度小于预期，则说明长度不够，\n此时，n将减半，恢复文件指针，重新读取。如果当n=1时长度仍然不够，就地encode/decode处理之。\n\n- ```encode_len```和```decode_len```用于计算输出的长度\n\n### 内部函数\n\n- 他们直接来自底层的C库，高性能，但是一般不需要在外部使用（除非是增加性能）\n\n```python\ndef _encode(data: BufferProtocol) -\u003e bytes: ...\n\ndef _encode_safe(data: BufferProtocol) -\u003e bytes: ...\n\ndef _decode(data: BufferProtocol) -\u003e bytes: ...\n\ndef _decode_safe(data: BufferProtocol) -\u003e bytes: ...\n\ndef _encode_into(data: BufferProtocol, dest: BufferProtocol) -\u003e int: ...\n\ndef _encode_into_safe(data: BufferProtocol, dest: BufferProtocol) -\u003e int: ...\n\ndef _decode_into(data: BufferProtocol, dest: BufferProtocol) -\u003e int: ...\n\ndef _decode_into_safe(data: BufferProtocol, dest: BufferProtocol) -\u003e int: ...\n\ndef is_64bits() -\u003e bool: ...\n```\n- ```_decode```在解码```b'='```开头的数据时***不安全***：***解释器异常***\n- ```_encode_into```和```_decode_into```直接操作缓冲区对象的底层指针，0拷贝，当然也和上面一样的问题，他们是没有检查的\n\n### ✨  v0.3更新 ✨ \n融合了 [CFFI](https://github.com/synodriver/pybase16384-cffi) 版本的成果，现在一个包可以同时在cpython和pypy上运行\n\n### 本机编译\n```\npython -m pip install setuptools wheel cython cffi\ngit clone https://github.com/synodriver/pybase16384\ncd pybase16384\ngit submodule update --init --recursive\npython setup.py bdist_wheel --use-cython --use-cffi\n```\n- 为了在windows上编译，需要加点料，把 [这个](https://gist.github.com/synodriver/8f1afae7b1a221754cb04ce417dc7e4d) 放进msvc的目录\n\n### 后端选择\n默认由py实现决定，在cpython上自动选择cython后端，在pypy上自动选择cffi后端，使用```B14_USE_CFFI```环境变量可以强制选择cffi","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynodriver%2Fpybase16384","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynodriver%2Fpybase16384","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynodriver%2Fpybase16384/lists"}