function encoder(){ var url="http://www.pdf995.com/samples/pdf.pdf"; var xhr=Ti.Network.createHTTPClient({ onload:function(){
var f=Ti.Utils.base64encode(this.responseData);
Ti.API.info(JSON.stringify(f));
var fs=Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(),'Mypdf.pdf');
fs.write(f);
},
onerror: function()
{
Ti.API.info("errr"+this.status);
}
});
xhr.open("GET",url);
xhr.send();
}
function decoder() { $.index.layout='composite'; if(Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(),'Mypdf.pdf').exists()) { var fs=Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(),'Mypdf.pdf'); //Ti.API.info("data"+fs.read().text+"data");
var s=Ti.Utils.base64decode(fs.read().text); //var temp=Ti.Filesystem.getFile(Ti.Filesystem.getTempDirectory(),'Mypdf1.pdf'); //temp.write(s);
Ti.API.info("sss"+s.toString()+"length"+s.length+"size"+s.size); //Ti.API.info("filee"+s.getFile()); Ti.API.info("texttt"+s.text); var blobStream = Ti.Stream.createStream({ source: s, mode: Ti.Stream.MODE_READ, }); var newBuffer = Ti.createBuffer({ length: s.length }); Ti.API.info("biuuffrrr"+blobStream.read(newBuffer)); var bytes = blobStream.read(newBuffer,0,s.length);
var html = '<!DOCTYPE html><html> <body>' +bytes+ '</body></html>';
var websView = Ti.UI.createWebView( { height:'100%', width:'100%', html:html } );
I am working on mobile project for ios.My question here is that how we can extract data from blob object without writing to a file.In my code variable s is a blob object 's' which i am getting after decoding a already encoded file. I want to show contents of blob object in webview. In my scenerio i am getting -1 as output o/p of 'byte's variable.Provide me a solution to it. Thanx in advance