Giter Club home page Giter Club logo

Comments (7)

pieroxy avatar pieroxy commented on July 24, 2024

If I try this on my test page : http://pieroxy.net/blog/pages/lz-string/demo.html

Your input string is actually 186 bytes (not 93 as you mention) and the compressed version is 41 bytes, so roughly 22% of the size of the input.

Remember that ALL strings are represented internally as UTF-16 in JavaScript, so no char takes less than 2 bytes.

from lz-string.

tomekmarchi avatar tomekmarchi commented on July 24, 2024

var Buffer = require('buffer').Buffer;
var str=dfhjksfhjas fgjdhsaf lSDFHLF ljljkahjdfhaljkhfdlknvjasnfhlHLEUYRIUORWYIUjdkjhafkjdhfhjdafclkj;

console.log(str.length + " characters, " + Buffer.byteLength(str, 'utf16') + " bytes"); //93 characters, 93 bytes
console.log(LZString.compress(str).length + " characters, " + Buffer.byteLength(LZString.compress(str), 'utf16') + " bytes"); //41 characters, 113 bytes

Node doesn't seem to agree, using utf-16...

from lz-string.

tomekmarchi avatar tomekmarchi commented on July 24, 2024

Looking to use this on the next version of LNKit. Would be advantageous to find out what exactly is going on here. When receiving data nodejs also reports a smaller byte count for the base64 data sent to server rather than the default UTF-16 function. I have a few assumptions but shoot me an email or add me on skype. Looking forward to figuring it out.

from lz-string.

pieroxy avatar pieroxy commented on July 24, 2024

I don't know what Buffer is, nor what Buffer.byteLength(str, 'utf16') does, but it contradicts the specs of unicode. I'll go with the spec. So either the method is buggy, either it's not doing what you think it's doing.

As a matter of fact, try this: Buffer.byteLength("a", "my mother is the best") and tell me what you see.

This suits well my experience with nodejs. Everything is so buggy that it's borderline unusable.

Anyways, LZString is made FOR THE BROWSER, not for the server. There is no point in encoding anything with LZString in nodejs (at least, not that I know of).

Why don't you start by telling me what you're trying to achieve first ?

from lz-string.

tmedwards avatar tmedwards commented on July 24, 2024

@tomekmarchi The problem is that you are using an invalid encoding name, so Buffer.byteLength() is falling back on its default encoding, which is utf8. The correct UTF-16 encoding names are utf16le and ucs2 (alias of the former). Try the following:

Buffer.byteLength(str, 'utf16le')

You can see this in the documentation.

from lz-string.

pieroxy avatar pieroxy commented on July 24, 2024

@tmedwards I'm sure this beyond-crappy behavior is documented somewhere, which is completely besides the point. How someone can design a piece of code that swallows errors this way is beyond me. Anyways, thanks for the tip.

To get back to the original point, with "utf16le" the size of the original string is "93 characters, 186 bytes" while the compressed version is be "41 characters, 82 bytes"

So LZString is actually compressing something.

Now, to get back to my original question, @tomekmarchi what exactly are you trying to achieve here?

from lz-string.

tomekmarchi avatar tomekmarchi commented on July 24, 2024

@tmedwards Good looks.
@pieroxy compression experimentation.

from lz-string.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.