On May 23, 9:53*am, Johannes Baagoe <baa...@baagoe.com> wrote:
> nick :
>
> >http://pressjs.googlecode.com/svn/trunk/build/test.html
>
> "Où qu'il réside, même aux îles Caïmans, tout Français inscrit au rôle
> paiera son dû dès Noël" (length 92) "compresses" to 118 characters.
Well, you obviously used the wrong text.
"banana cabana banana cabana banana cabana banana cabana banana
cabana" (length 69) compresses to 44 characters!
> >http://code.google.com/p/pressjs/sou...#svn/trunk/src
>
> Fromhttp://code.google.com/p/pressjs/source/browse/trunk/src/compdict.js:
>
> * // Populate table with all possible character codes.
> * for(var i = 0; i < 256; ++i) {
> * * var str = String.fromCharCode(i);
> * * this.hashtable[str] = this.nextcode++;
> * } *
>
> What about character codes >= 256?
I'm pretty sure those characters aren't allowed in a javascript
document? I'm not really sure what's going on there though, I was
puzzled by that bit as well. See my next paragraph.
> My general impression is that you are complicating things for no reason.
> Why use constructors, prototypes and fancy "//#" pseudo-cpp directives?
> Just one file which defines the two functions that compress and expand
> would be much easier both to write and to review.
Yeah, that stuff is all part of another GPL program I ripped off to
make this compressor, which in turn is a pretty much direct port of
some c++ code, so it has a very class-like design. I've been going
through and making it more object-based, and trying to learn the
algorithm at the same time. Eventually I'd like to replace all of that
code, but for now I just wanted to see if this whole idea was viable.
Well, the cpp directives were my idea. I like to be able to separate
the files into logical units, and ifdef comes in handy when building
multiple similar-but-different targets (like stand-alone vs embedded
decompressor).
I'm definitely considering merging instream and outstream
functionalities into the compressor / decompressor, but I think I like
the dictionaries in separate files for now.
> (I assume that you are doing this for fun, for the challenge of writing
> a compressor in javascript. If it is in order to reduce bandwidth
> in real applications on the Web, enabling gzip on the server is much
> more efficient.)
Yeah, I'm mostly doing it to see if it can be done. Next I want to
experiment with a different compression algorithm or one of the
variations on LZW. Server-side gzip is obviously the better
alternative if it's available; however that's not always the case (see
my response to Sean) and so we have things like "packer" and maybe
this thing.