<i id='tw5Pk'><tr id='tw5Pk'><dt id='tw5Pk'><q id='tw5Pk'><span id='tw5Pk'><b id='tw5Pk'><form id='tw5Pk'><ins id='tw5Pk'></ins><ul id='tw5Pk'></ul><sub id='tw5Pk'></sub></form><legend id='tw5Pk'></legend><bdo id='tw5Pk'><pre id='tw5Pk'><center id='tw5Pk'></center></pre></bdo></b><th id='tw5Pk'></th></span></q></dt></tr></i><div id='tw5Pk'><tfoot id='tw5Pk'></tfoot><dl id='tw5Pk'><fieldset id='tw5Pk'></fieldset></dl></div>
    <tfoot id='tw5Pk'></tfoot><legend id='tw5Pk'><style id='tw5Pk'><dir id='tw5Pk'><q id='tw5Pk'></q></dir></style></legend>

    <small id='tw5Pk'></small><noframes id='tw5Pk'>

      <bdo id='tw5Pk'></bdo><ul id='tw5Pk'></ul>

        使用 localStorage 进行 javascript 字符串压缩

        javascript string compression with localStorage(使用 localStorage 进行 javascript 字符串压缩)
          <bdo id='D3Itt'></bdo><ul id='D3Itt'></ul>
          <tfoot id='D3Itt'></tfoot>
        • <small id='D3Itt'></small><noframes id='D3Itt'>

            <i id='D3Itt'><tr id='D3Itt'><dt id='D3Itt'><q id='D3Itt'><span id='D3Itt'><b id='D3Itt'><form id='D3Itt'><ins id='D3Itt'></ins><ul id='D3Itt'></ul><sub id='D3Itt'></sub></form><legend id='D3Itt'></legend><bdo id='D3Itt'><pre id='D3Itt'><center id='D3Itt'></center></pre></bdo></b><th id='D3Itt'></th></span></q></dt></tr></i><div id='D3Itt'><tfoot id='D3Itt'></tfoot><dl id='D3Itt'><fieldset id='D3Itt'></fieldset></dl></div>

                <legend id='D3Itt'><style id='D3Itt'><dir id='D3Itt'><q id='D3Itt'></q></dir></style></legend>
                  <tbody id='D3Itt'></tbody>
                • 本文介绍了使用 localStorage 进行 javascript 字符串压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个项目中使用 localStorage,它需要存储 lots 的数据,主要是 int、bool 和 string 类型.我知道 javascript 字符串是 unicode,但是当存储在 localStorage 中时,它们会保持 unicode 吗?如果是这样,有没有办法可以压缩字符串以使用 unicode 字节中的所有数据,或者我应该只使用 base64 并减少压缩?所有数据都将存储为一个大字符串.

                  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 根本不会做太多压缩,数据已经在 base 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 中时,它们是否保持 unicode?"

                  Web Storage 工作草案 将本地存储值定义为DOM 字符串.DOMStrings 被定义为使用 UTF-16 编码 的 16 位单元.所以是的,它们仍然是 Unicode.

                  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.

                  有没有办法可以压缩字符串以使用 unicode 字节中的所有数据...?

                  Base32k"编码应该为每个字符提供 15 位.base32k 类型编码利用了 UTF-16 字符中的完整 16 位,但会丢失一点以避免在双字字符上出错.如果您的原始数据采用 base64 编码,则每个字符仅使用 6 位.将这 6 位编码为 base32k 应将其压缩为原始大小的 6/15 = 40%.请参阅 http://lists.xml.org/archives/xml-dev/200307/msg00505.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.

                  为了进一步减小大小,您可以将 base64 字符串解码为完整的 8 位二进制文件,使用一些已知的压缩算法对其进行压缩(例如,请参阅 gzip的javascript实现),然后base32k编码压缩输出.

                  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.

                  这篇关于使用 localStorage 进行 javascript 字符串压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                    <tbody id='Zkslr'></tbody>
                        <tfoot id='Zkslr'></tfoot>

                      • <legend id='Zkslr'><style id='Zkslr'><dir id='Zkslr'><q id='Zkslr'></q></dir></style></legend>
                      • <i id='Zkslr'><tr id='Zkslr'><dt id='Zkslr'><q id='Zkslr'><span id='Zkslr'><b id='Zkslr'><form id='Zkslr'><ins id='Zkslr'></ins><ul id='Zkslr'></ul><sub id='Zkslr'></sub></form><legend id='Zkslr'></legend><bdo id='Zkslr'><pre id='Zkslr'><center id='Zkslr'></center></pre></bdo></b><th id='Zkslr'></th></span></q></dt></tr></i><div id='Zkslr'><tfoot id='Zkslr'></tfoot><dl id='Zkslr'><fieldset id='Zkslr'></fieldset></dl></div>

                        <small id='Zkslr'></small><noframes id='Zkslr'>

                          <bdo id='Zkslr'></bdo><ul id='Zkslr'></ul>