Javascript 客户端数据压缩

标签 javascript compression processing.js

我正在尝试通过 processingjs 开发画笔应用程序。 此 API 具有函数 loadPixels(),可将 RGB 值加载到数组中。 现在我想将数组存储在服务器数据库中。

问题是数组的大小,当我转换为字符串时大小为 5 MB。

最好的解决方案是在 javascript 级别进行压缩吗?怎么做?

最佳答案

参见 http://rosettacode.org/wiki/LZW_compression#JavaScript对于 LZW 压缩示例。它最适用于具有重复模式的较长字符串。

来自Wikipedia article在 LZW 上:

A dictionary is initialized to contain the single-character strings corresponding to all the possible input characters (and nothing else except the clear and stop codes if they're being used). The algorithm works by scanning through the input string for successively longer substrings until it finds one that is not in the dictionary. When such a string is found, the index for the string less the last character (i.e., the longest substring that is in the dictionary) is retrieved from the dictionary and sent to output, and the new string (including the last character) is added to the dictionary with the next available code. The last input character is then used as the next starting point to scan for substrings.

In this way, successively longer strings are registered in the dictionary and made available for subsequent encoding as single output values. The algorithm works best on data with repeated patterns, so the initial parts of a message will see little compression. As the message grows, however, the compression ratio tends asymptotically to the maximum.

关于Javascript 客户端数据压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2252465/

相关文章:

javascript - 将 PHP 值显示到不刷新的页面

javascript - Angular 7 3D 模型查看器

c# - 如何在 Simple OData Client 中启用 gzip 压缩?

c# - 我需要 C# 中的 Shannon–Fano 算法

javascript - 用 javascript 压缩 XML 文件?

javascript - 处理js+javascript+处理

javascript - d3.js 热图未正确显示数据

javascript - Firefox Addon 中的 JQuery 导致多个警告

javascript - 处理 Sketch 无法在 JavaScript 模式下工作

javascript - 结合 Processing.js 和 Web Worker 的强大功能