在base64编码之前缩短字符串以使其更短的无损压缩方法?
刚刚构建了一个用于预览 HTML 文档的小型 Web 应用程序,该应用程序生成的 URL:s 包含 base64 编码数据中的 HTML(以及所有内联 CSS 和 Javascript).问题是,URL:s 很快就会变得有点长.首先压缩字符串而不丢失数据的事实上的"标准方式(最好是Javascript)是什么?
just built a small webapp for previewing HTML-documents that generates URL:s containing the HTML (and all inline CSS and Javascript) in base64 encoded data. Problem is, the URL:s quickly get kinda long. What is the "de facto" standard way (preferably by Javascript) to compress the string first without data loss?
PS;前段时间我在学校读到关于 Huffman 和 Lempel-Ziv 的文章,我记得我真的很喜欢 LZW :)
PS; I read about Huffman and Lempel-Ziv in school some time ago, and I remember really enjoying LZW :)
找到解决方案;似乎 rawStr => utf8Str => lzwStr => base64Str 是要走的路.我正在进一步致力于在 utf8 和 lzw 之间实现霍夫曼压缩.到目前为止的问题是,当编码为 base64 时,太多的字符会变得很长.
Solution found; seems like rawStr => utf8Str => lzwStr => base64Str is the way to go. I'm further working on implementing huffman compression between utf8 and lzw. Problem so far is that too many chars become very long when encoded to base64.
推荐答案
查看这个答案.它提到了 LZW 压缩/解压缩的功能(通过 http://jsolait.net/,特别是 http://jsolait.net/browser/trunk/jsolait/lib/codecs.js).
Check out this answer. It mentions functions for LZW compression/decompression (via http://jsolait.net/, specifically http://jsolait.net/browser/trunk/jsolait/lib/codecs.js).
相关文章