ironer/base62shrink
Composer 安装命令:
composer require ironer/base62shrink
包简介
Simple javascript to perform LZW compression on longer structured or repetitive UTF8 data (like stringified JSON) to some universally web safe form. Simple PHP class for server side data processing.
关键字:
README 文档
README
Simple javascript to perform LZW compression on longer structured or repetitive UTF8 data (like stringified JSON) to some universally web safe form. Simple PHP class for server side data processing.
Added: Possibility to encode the compressed base8 data to base32k for storing in local storage.
Demo: http://b62s.ironer.cz
Used sources:
- LZW compression: http://rosettacode.org/wiki/LZW_compression#JavaScript
- UTF8 encode & decode: http://ecmanaut.blogspot.cz/2006/07/encoding-decoding-utf8-in-javascript.html
- Base32k encode & decode: http://lists.xml.org/archives/xml-dev/200307/msg00505.html
Base62shrink uses LZW compression and some javascript data transformations to prevent wasting of bit information and simply encode the resulting LZW array of indexes to base62 string of safe chars (a-zA-Z0-9). Thus on some data examples makes the base62 encoded data shorter instead of 33% increase of standard base64 encode function.
Maybe is the same principle used in some compressions, but I couldn't find anything short and simple.
If anyone ever wonders, how the code works, here is some short description:
-
UTF8 encoded string is compressed by LZW to array of integer indexes in dictionary of concatenated substrings.
-
The integers in array are going to be compressed and each of them encoded to base6, then whole array converted to string with separator and minus sign effectively replaced by '6' and '7' to get base8 string.
-
The bit length of array of integers is compressed by replacing every element except 1st one by the integer calculated as delta from previous element.
-
The deltas in array are changed from base10 to base6 for further compression.
-
The array is joined to string by char '6' as separator.
-
Every occurrence of '6' separator before negative delta in base6 is replaced by '7' and the minus sign is removed.
-
-
Resulting base8 string from step 2 is going to be encoded to base62. 2 chars to 1 char.
-
Additional base8 value is added at the start of the string as flag of redundant char added at the end. Thus odd length string has just the flag value at the start added to give even length, while even length string has different flag value at the start and redundant value at the end to give even length.
-
The number 7 represents separator followed by minus in the base8 string, thus it won't be ever directly followed by 6 or 7 (separator or separator with minus). That's why highest value of 2 directly following chars in the base8 string doesn't go over 61 in base10 and used base62 is enough.
-
The encoding to base62 is pretty straightforward as the base8 string is even length now and each pair of following chars represents one of 62 values.
-
-
As mentioned above, the number 7 is never followed by 6 or 7. This works vice versa. So there will be never '66' or '67' in the base8 string, which leaves characters at index 54 and 55 ('2' and '3') from base62 encoding string unused. The combination '70' in base8 string is impossible too, as it would stand for: separator followed by minus sign followed by zero, so the character at index 56 ('4') won't appear in the resulting base62 string either. Thus characters '2', '3' and '4' can be used as separators or eof for encoded strings.
Maybe someone finds this script useful ;-)
ironer/base62shrink 适用场景与选型建议
ironer/base62shrink 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 259 次下载、GitHub Stars 达 3, 最近一次更新时间为 2013 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「compression」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ironer/base62shrink 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ironer/base62shrink 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ironer/base62shrink 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Yii2 integration for TinyPng
Smart compressed files extractor
Laravel integration for the imagify.io API
Asset Management for PHP
统计信息
- 总下载量: 259
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-05-11