Skip to main content

base16384 encode and decode

Project description

✨ pybase16384 ✨

The python binding for base16384

一种神奇的编码

pypi python implementation wheel license action

使用

  • 编码/解码文本
>>> import pybase16384 as pybs
>>> pybs.encode_string('hello!!')
'栙擆羼漡'
>>> pybs.decode_string('栙擆羼漡')
'hello!!'
  • 编码文件
from io import BytesIO

import pybase16384 as pybs

with open("input.pcm", "rb") as f:
    data = f.read()
for i in range(1):
    pybs.encode_file(BytesIO(data), open("output2.pcm", 'wb'), True)
  • 解码文件
from io import BytesIO

import pybase16384 as pybs

with open("output2.pcm", "rb") as f:
    data = f.read()
for i in range(1):
    pybs.decode_file(BytesIO(data), open("input2.pcm", 'wb'))

公开函数

def encode_len(dlen: int) -> int: ...

def decode_len(dlen: int, offset: int) -> int: ...

def encode(data: bytes) -> bytes: ...

def decode(data: bytes) -> bytes: ...

def decode_file(input: BinaryIO, output: BinaryIO, buf_rate: int = 10) -> None: ...

def encode_file(input: BinaryIO, output: BinaryIO, boolwrite_head: bool = False, buf_rate: int = 10) -> None: ...

def encode_from_string(data: str, write_head: bool = False) -> bytes: ...

def encode_to_string(data: bytes) -> str: ...

def encode_string(data: str) -> str: ...

def decode_from_bytes(data: bytes) -> str: ...

def decode_from_string(data: str) -> bytes: ...

def decode_string(data: str) -> str: ...
  • write_head将显式指明编码出的文本格式(utf16be),以便文本编辑器(如记事本)能够正确渲染,一般在写入文件时使用。

  • buf_rate指定读取文件的策略。当它为n时,则表示一次读取7n或者8n个字节。如果读到的字节长度小于预期,则说明长度不够, 此时,n将减半,恢复文件指针,重新读取。如果当n=1时长度仍然不够,就地encode/decode处理之。

  • encode_lendecode_len用于计算输出的长度

内部函数

  • 他们直接来自底层的C库,高性能,但是一般不需要在外部使用(除非是增加性能)
def _encode(data: BufferProtocol) -> bytes: ...

def _decode(data: BufferProtocol) -> bytes: ...

def _encode_into(data: BufferProtocol, dest: BufferProtocol) -> int: ...

def _decode_into(data: BufferProtocol, dest: BufferProtocol) -> int: ...
  • _decode在解码b'='开头的数据时不安全解释器异常
  • _encode_into_decode_into直接操作缓冲区对象的底层指针,0拷贝,当然也和上面一样的问题,他们是没有检查的

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybase16384-0.2.2rc1.tar.gz (132.6 kB view hashes)

Uploaded Source

Built Distributions

pybase16384-0.2.2rc1-cp310-cp310-win_amd64.whl (193.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pybase16384-0.2.2rc1-cp310-cp310-manylinux2014_x86_64.whl (227.8 kB view hashes)

Uploaded CPython 3.10

pybase16384-0.2.2rc1-cp310-cp310-macosx_10_15_x86_64.whl (200.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pybase16384-0.2.2rc1-cp39-cp39-win_amd64.whl (193.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pybase16384-0.2.2rc1-cp39-cp39-manylinux2014_x86_64.whl (227.7 kB view hashes)

Uploaded CPython 3.9

pybase16384-0.2.2rc1-cp39-cp39-macosx_10_15_x86_64.whl (200.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pybase16384-0.2.2rc1-cp38-cp38-win_amd64.whl (193.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pybase16384-0.2.2rc1-cp38-cp38-manylinux2014_x86_64.whl (227.4 kB view hashes)

Uploaded CPython 3.8

pybase16384-0.2.2rc1-cp38-cp38-macosx_10_14_x86_64.whl (198.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pybase16384-0.2.2rc1-cp37-cp37m-win_amd64.whl (192.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pybase16384-0.2.2rc1-cp37-cp37m-manylinux2014_x86_64.whl (226.1 kB view hashes)

Uploaded CPython 3.7m

pybase16384-0.2.2rc1-cp37-cp37m-macosx_10_14_x86_64.whl (198.8 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pybase16384-0.2.2rc1-cp36-cp36m-win_amd64.whl (192.8 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

pybase16384-0.2.2rc1-cp36-cp36m-manylinux2014_x86_64.whl (226.6 kB view hashes)

Uploaded CPython 3.6m

pybase16384-0.2.2rc1-cp36-cp36m-macosx_10_14_x86_64.whl (198.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page