I am trying to read a .PNG file using Titanium 1.8.1 Here is my code to read file.
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'KS_nav_views.png');
var blob = f.read();
When I create a new file using the above blob object, the new file thus created is not same as the original file. Here is my code to create the new file.
var outputDir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,'output');
outputDir.createDirectory();
var newFile = Titanium.Filesystem.getFile(outputDir.nativePath,'outFile.png');
var test = newFile.write(blob);
if ( test === false){
Ti.API.debug("Write Error");
}
Ti.API.debug("Write complete? " + test);
The outFile.png gets created but the problem is that It is not a valid image file. Also the size of the file is around 53 bytes, whereas my input file was 1kb.
The same code works fine if we use a simple text file as input and try to create duplicate output file.
You do not need to do read() do it like this:
var t = Titanium.Filesystem.getFile(tempDataDirectory, 'a.json');
var o = Titanium.Filesystem.getFile(onlineDataDirectory, 'b.json');
o.write(t);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With