https://github.com/shigma/base16384.js
Base16384 encoder and decoder
https://github.com/shigma/base16384.js
Last synced: 8 months ago
JSON representation
Base16384 encoder and decoder
- Host: GitHub
- URL: https://github.com/shigma/base16384.js
- Owner: shigma
- License: mit
- Created: 2022-06-22T18:22:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-08T16:19:45.000Z (over 3 years ago)
- Last Synced: 2025-04-30T18:04:58.432Z (8 months ago)
- Language: TypeScript
- Size: 19.5 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Base16384
[](https://codecov.io/gh/shigma/base16384)
[](https://www.npmjs.com/package/base16384)
[](https://www.npmjs.com/package/base16384)
[](https://github.com/shigma/base16384/blob/master/LICENSE)
A unicode-based encoding scheme that presents binary data (sequence of 8-bit bytes) in sequences of 14-bit printable Chinese characters. It saves 17% space compared to base64.
Inspired by [fumiama/base16384](https://github.com/fumiama/base16384).
## Description
Base16384 uses 16384 (214) Chinese characters (from `\u4E00` to `\u8DFF`) to represent binary data.
If the length of the binary data is not a multiple of 7, we will add a `\u3D0x` (where x is the remainder modulo 7) after the output.
## Comparison
| | Base64 | Base16384 |
| --------- |:---------------:|:-----------------:|
| Overhead | 33% | 14% |
| Charset | `[0-9a-zA-Z+/]` | `[\u4E00-\u8DFF]` |
| Example | `RXhhbXBsZQ==` | `彞吖菁穥㴀` |
## Usage
```ts
import { decode, encode } from 'base16384'
const buffer = encode('Example') // Uint16Array
new TextDecoder().decode(decode(buffer)) // 'Example'
```
## API
### encode(data)
- data: `string | Uint8Array` original binary data
- returns: `Uint16Array` base16384-encoded data
Encode binary data to base16384.
### decode(data)
- data: `string | Uint16Array` base16384-encoded data
- returns: `Uint8Array` original binary data
Decode base16384 to binary data.