views:

658

answers:

1

I've been working on an app running in a browser and I would like to try to convert it to an AIR one.

In my web app, after loading the document, I am loading a text file in a string with jquery.

var info;
$.get('media/info.txt',function(data) {
   info=data;
   alert("the info is "+info.length+" bytes long");
});

In my AIR app, after loading the document locally, I am loading the SAME text file (but here hosted locally with the AIR app) in a string with the AIR file API.

var info;
var file=air.File.applicationDirectory.resolvePath("media/info.txt");
var filestream=new air.FileStream();
filestream.addEventListener(air.Event.COMPLETE, function() {
   info=filestream.readUTFBytes(filestream.bytesAvailable);
   alert("the info is "+info.length+" bytes long");
});
filestream.openAsync(file, air.FileMode.READ);

The two alerts above give me two different values for the same file, whereas my app's working well in a browser, the AIR info is bigger and seems to introduce some untrackable characters that broke my app!

I guessed this may have to do with the reading method used in AIR (UTF shit) but I cannot find another reading that actually worked.

Can someone give me a hint to get the same data in both cases?

+1  A: 

The readUTFBytes() expects to read UTF-8 encoded characters. Can you check if your original file is UTF-8? A good text-editor might be of help.

dirkgently
Hello Dirk,I am on Windows with notepad, wordpad and Crimson Editor...How could I check the encoding of my file?For info the file has been edited by me on notepad. Since it is written by my app and saved each time to a server running on the Django Python framework: how do JS, Py, Django encode?
Off the top of my head -- probably you are reading in UTF-16 data.
dirkgently
Dunno about Crimson. Try opening in Mozilla/IE and see View > Character Encoding. Choose one where the text appears flawlessly. This is not a foolproof way though.
dirkgently
Dirk,I solved my problem. By looking the charCode, I found I had some additional "charCode=13" in the AIR version. I skipped them and now my app is working (quite) well in AIR too. Thanks for your help.
charCode 13 is enter key. and I thought they are mostly harmless.
dirkgently