www.webdeveloper.com
Results 1 to 7 of 7

Thread: Getting binary data. Lost of 128+ chars

  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Getting binary data. Lost of 128+ chars

    Hello!

    I am trying to download an image by ajax (for some reasons i will not explain here).
    But i am getting all 127-255 bytes seted to 65533.
    Example:
    From the image
    Code:
    66 77 54 16 0 0 0 0 0 0 54 0 0 0 40 0 0 0 32 0 0 0 32 0 0 0 1 0 32 0 0 0 0 0 0 0 0 0 19 11 0 0 19 11 0 0 0 0 0 0 0 0 0 0 255 255 255 0 255 255 255 0 0 0 0 28 0 0 0 65 0 0 0 37 135 135 135 0 145 145 144 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.....
    i get
    Code:
    66 77 54 16 0 0 0 0 0 0 54 0 0 0 40 0 0 0 32 0 0 0 32 0 0 0 1 0 32 0 0 0 0 0 0 0 0 0 19 11 0 0 19 11 0 0 0 0 0 0 0 0 0 0 65533 65533 65533 0 65533 65533 65533 0 0 0 0 28 0 0 0 65 0 0 0 37 65533 65533 65533 0 65533 65533 65533 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0....
    I don't understand why that occur and i cannot use server-side base64 encoding.

    Here the code i am using:
    Code:
    		http = new XMLHttpRequest();
    		http.onreadystatechange = new Function("",
    		"callbacksend('"+url+"');");
    		http.open("post", "http://www.myserver.com/Icon.bmp", true);
    		http.setRequestHeader("Accept-Charset", "utf-8");
    		http.send(null);
    
    function callbacksend(url){
    	if(http.readyState == 4){
    		if(http.status == 200){
    			// todo ok
    			for( var i=0; i < 100; i++){
    				document.body.appendChild(document.createTextNode(" " + http.responseText.charCodeAt(i)));
    			}			
    		}
    	}
    };
    Thx for any help and sorry for my poor english

    Escain

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    It's probably UTF-8 that's doing it. Try ISO-8859-1 instead.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Jul 2011
    Posts
    3

    Question

    thanks for reply, i tried it but no changes :S

    I also uploaded all the test to my server if anyone wants to try it with complete source code:
    http://www.leyendaepica.es/include2.html

    With this example, i get the following result:
    Code:
    Size: 306
    66 77 50 1 0 0 0 0 0 0 54 0 0 0 40 
    0 0 0 9 0 0 0 9 0 0 0 1 0 24 0 0 0 
    0 0 65533 0 0 0 65533 14 0 0 
    65533 14 0 0 0 0 0 0 0 0 0 0 
    36 36 36 82 82 82 76 76 76 100 
    88 100 84 80 84 76 76 76 76 76 
    76 82 82 82 36 36 36 0 82 82 82 
    65533 65533 65533 
    65533 65533 65533
    ......

  4. #4
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    65533 (or 0xFFFD) is a replacement character, used to replace a character whose value is unknown or unrepresentable in Unicode.

    But this explains how to get around that.

    There are two pieces of magic. The first is:

    http.overrideMimeType('text/plain; charset=x-user-defined');

    Which tells the browser: Don't treat it as characters. Don't treat it as anything. Just pass it through.

    Now you should be seeing different, but still large, numbers. It seems that an 0xF7 byte will be in the high-order position. I couldn't find any explanation why this happens, but nonetheless we can remove it with a second piece of magic:

    http.responseText.charCodeAt(i) & 0xff

    And that'll do it. :-)
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  5. #5
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    I just discovered that this solution doesn't work in IE. I'm checking into it.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  6. #6
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Looks like you need to use VBScript if it's ever going to work in IE. It gets pretty ugly. But fortunately someone wrapped the ugliness in a library.

    You can read the source if you're curious what's going on under the hood. Otherwise, just go ahead and load the library into your page and use its API.

    Code:
    <script type="text/javascript" src="http://www.heypage.com/nagoon97/BinFileReader/BinFileReader.js"></script>
    <script type="text/javascript">
    var bmpFile = new BinFileReader("Icon.bmp");
    
    document.body.appendChild(document.createTextNode("Size: " + bmpFile.getFileSize()));
    document.body.appendChild(document.createElement("br"));
    for (var i = 0; i < bmpFile.getFileSize(); i++) {
        document.body.appendChild(document.createTextNode(" " + bmpFile.readString(1, i).charCodeAt(0)));
    }
    </script>
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  7. #7
    Join Date
    Jul 2011
    Posts
    3

    Thumbs up

    Thanks a lot its really a nice job

    I have tried and it run well. I also discovered that it's possible to read directly in the correct charset without the conversion byte to byte ( & 0xff ) changing only that line:
    Code:
    http.overrideMimeType('text/plain; charset=iso-8859-1');
    thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles