Lossless compression method to shorten string before base64 encoding to make it shorter?(在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).
这篇关于在base64编码之前缩短字符串以使其更短的无损压缩方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在base64编码之前缩短字符串以使其更短的无损压缩方法?
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
