Javascript客户端数据压缩 [英] Javascript client-data compression

查看:127
本文介绍了Javascript客户端数据压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过processingjs开发一个画笔应用程序。
此API具有函数 loadPixels(),它会将RGB值加载到数组中。
现在我想将数组存储在服务器db中。

I am trying to develop a paint brush application thru processingjs. This API has function loadPixels() that will load the RGB values in to the array. Now i want to store the array in the server db.

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

The problem is the size of the array, when i convert to a string the size is 5 MB.

最好的解决方案是在javascript级别进行压缩?如何做?

Is the best solution is to do compression at javascript level? How to do it?

推荐答案

请参阅 http://rosettacode.org/wiki/LZW_compression#JavaScript 的LZW压缩示例。

See http://rosettacode.org/wiki/LZW_compression#JavaScript for an LZW compression example. It works best on longer strings with repeated patterns.

LZW上的维基百科文章


字典初始化为包含
- 字符串
对应于所有可能的
输入字符(除非使用
,否则除了清除和停止代码之外没有别的
)。算法
的工作原理是扫描输入
字符串连续更长的
子字符串,直到找到
不在字典中。当找到这样的
字符串时,从$ b中检索
字符串的索引减去最后一个字符(即,

字典中最长的子字符串) $ b字典并发送到输出,并将
新字符串(包括最后的
字符)添加到字典
中,并使用下一个可用代码。最后的
输入字符然后用作
下一个起始点以扫描
子字符串。

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客户端数据压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆