1

The scenario of my problem: Some data in a file that should be compressed to smaller size. The content of this file is required by the HTML on the fly by using the javascript.

So basically i need to encode that data using C and decode that data using javascript and provide it to HTML.

I am just curious to know if this thing is possible or not, because while decoding we need the binary heap.

Ashish Yadav
  • 1,667
  • 6
  • 20
  • 26
  • To begin with, there are data structures libraries for javascript, check [this](http://stackoverflow.com/questions/5909452/javascript-data-structures-library). – axiom Feb 11 '13 at 14:07
  • Your file will be a binary file, let say Huffman codewords. one after another. Then yes, you can read write a binary file in c, and read a binary file in Javascript. – UmNyobe Feb 11 '13 at 14:09
  • 2
    Wouldn't it be better to get your server to serve the object stream over a GZIP-compressed connection? But yes, there's no reason you can't implement any decompression scheme in JavaScript. You can certainly represent a tree structure in JavaScript if that's what you're worried about. – Rup Feb 11 '13 at 14:12
  • @Rup The main cause of worry is that the compression has to be done in C and the decompression of has to be done in javascript.Also this has to be done client side, so no server in the picture. – Ashish Yadav Feb 11 '13 at 14:17
  • 1
    OK, I might be wrong: [this question](http://stackoverflow.com/questions/327685/is-there-a-way-to-read-binary-data-into-javascript) says JavaScript can't handle binary data easily, and there's probably little point compressing data if you then need to e.g. base64 it for transmission or storage. But if there's no server, where's the data coming from?? You're using a C program to generate an HTML file with the compressed data embedded in it? – Rup Feb 11 '13 at 14:30
  • See currently C program generates some files lets call them a.info and javascript reads these files to show info on HTML.I want to compress these files(they take a lot of space) and decompress them using.These info files are generated some time ago and at the time of showing HTML their data is collatted. – Ashish Yadav Feb 11 '13 at 14:36

1 Answers1

3

Yes, it's possible. Javascript has bit operations that take the value as a 32-bit integer, even though it's stored in a float. That will permit you to do the same things that you do in C to compress and decompress data. It won't be as fast, but it will work.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158