JavaScript的字符串COM pression带的localStorage [英] javascript string compression with localStorage

查看:174
本文介绍了JavaScript的字符串COM pression带的localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的localStorage 的一个项目,它需要存储的数据的大量的大多是int类型,布尔和字符串的。我知道的JavaScript字符串是单向code,但保存在的localStorage 时,做他们留单code?如果是这样,有没有办法我可以融为一体preSS字符串使用的所有数据在UNI code字节,或者我应该只使用Base64和少COM pression?所有的数据将被存储为一个大字符串。

I am using localStorage in a project, and it will need to store lots of data, mostly of type int, bool and string. I know that javascript strings are unicode, but when stored in localStorage, do they stay unicode? If so, is there a way I could compress the string to use all of the data in a unicode byte, or should i just use base64 and have less compression? All of the data will be stored as one large string.

编辑:现在,我想想,会的base64起不到多大COM pression可言,数据已经在基地64, A-ZA-Z0-9;: 65个字符。

Now that I think about it, base64 wouldn't do much compression at all, the data is already in base 64, a-zA-Z0-9 ;: is 65 characters.

推荐答案

存储在localStorage的时候,做他们留单code吗?

借助 Web存储工作草案本地存储值定义为的DOMString。 DOMStrings作为使用的16位序列定义 UTF-16编码。所以,是的,他们留的Uni code。

The Web Storage working draft defines local storage values as DOMString. DOMStrings are defined as sequences of 16-bit units using the UTF-16 encoding. So yes, they stay Unicode.

有没有办法我可以融为一体preSS字符串使用的所有数据在UNI code字节 ...

Base32k编码应该给你每个字符15位。一个base32k型编码充分利用了全16位的UTF-16字符,但失去了一点,以免绊倒在双字字符。如果你的原始数据采用Base64 EN codeD,它仅使用每个字符6位。编码的那些6位转换成base32k应该玉米preSS它到其原始尺寸的6/15 = 40%。见<一href=\"http://lists.xml.org/archives/xml-dev/200307/msg00505.html\">http://lists.xml.org/archives/xml-dev/200307/msg00505.html和<一个href=\"http://lists.xml.org/archives/xml-dev/200307/msg00507.html\">http://lists.xml.org/archives/xml-dev/200307/msg00507.html.

"Base32k" encoding should give you 15 bits per character. A base32k-type encoding takes advantage of the full 16 bits in UTF-16 characters, but loses a bit to avoid tripping on double-word characters. If your original data is base64 encoded, it only uses 6 bits per character. Encoding those 6 bits into base32k should compress it to 6/15 = 40% of its original size. See http://lists.xml.org/archives/xml-dev/200307/msg00505.html and http://lists.xml.org/archives/xml-dev/200307/msg00507.html.

有关大小甚至进一步减少,你可以去code你的base64字符串到他们的完整的8位二进制,玉米preSS它们与一些已知的COM pression算法(如见的javascript实施的gzip 的),然后base32k EN code中的COM pressed输出。

For even further reduction in size, you can decode your base64 strings into their full 8-bit binary, compress them with some known compression algorithm (e.g. see javascript implementation of gzip), and then base32k encode the compressed output.

这篇关于JavaScript的字符串COM pression带的localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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