[TIMOB-1658] iOS: Ti.File.write always returns false for binary data
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-02-11T21:20:28.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 3.2.0 |
Components | iOS |
Labels | api, exalture, qe-closed-3.2.2, supportTeam |
Reporter | zcopley |
Assignee | Ingo Muschenetz |
Created | 2011-04-15T02:58:37.000+0000 |
Updated | 2014-03-10T09:28:54.000+0000 |
Description
On the iPhone, Titanium.Filesystem.File.write always returns
false when writing binary data to files. It works correctly for
text data. (There doesn't seem to be a problem on Android.)
var appDirName = Titanium.Filesystem.applicationDataDirectory;
var txtFile = Titanium.Filesystem.getFile(appDirName, 'foobar.txt');
var binFile = Titanium.Filesystem.getFile(appDirName, 'foobar.bin');
var text = "Sudo make me a sandwich.";
if (!txtFile.exists()) {
Titanium.API.debug("File " + txtFile.name + " does not exist yet.");
}
if (!binFile.exists()) {
Titanium.API.debug("File " + binFile.name + " does not exist yet.");
}
if (txtFile.write(text)) {
Titanium.API.debug("I successfully wrote text to the file.");
} else {
Titanium.API.debug("I was not able to write text to the file. Oh no!");
}
var blob = Titanium.Utils.base64decode(text); // make some bin data
if (binFile.write(blob)) {
Titanium.API.debug("I successfully wrote a blob to the file.");
} else {
Titanium.API.debug("I was not able to write a blob to the file. Oh no!");
}
// Do they exist now?
if (txtFile.exists()) {
Titanium.API.debug(txtFile.name + " exists, contents: " + txtFile.read());
}
if (binFile.exists()) {
// Note: Titanium.Filesystem.File.size attribute not mentioned in the API docs
Titanium.API.debug(binFile.name + " exists, size: " + binFile.size);
}
iPhone:
[DEBUG] File foobar.txt does not exist yet.
[DEBUG] File foobar.bin does not exist yet.
[DEBUG] I successfully wrote text to the file.
[DEBUG] I was not able to write a blob to the file. Oh no!
[DEBUG] foobar.txt exists, contents: Sudo make me a sandwich.
[DEBUG] foobar.bin exists, size: 15
Android:
D/TiAPI ( 532): (kroll$1) [615,1099] File foobar.txt does not exist yet.
D/TiAPI ( 532): (kroll$1) [21,1120] File foobar.bin does not exist yet.
D/TiAPI ( 532): (kroll$1) [154,1274] I successfully wrote text to the file.
D/TiAPI ( 532): (kroll$1) [725,1999] I successfully wrote a blob to the file.
D/TiAPI ( 532): (kroll$1) [87,2086] foobar.txt exists, contents: Sudo make me a sandwich.
D/TiAPI ( 532): (kroll$1) [18,2104] foobar.bin exists, size: 15
I confirmed this running 1.4.1 on iOS 4.
Bug is still valid, occurs in: TiMOB sdk version: 1.7.2, 1.8.0.v20111103144656 Studio version: 1.0.7.201111022004 OS version: Mac OS X Lion Devices tested on: ipod 4.0.2, iphone 5.0
Still a bug as of today with the latest SDK
Still valid SDK 2.2.0.f9e938d
Still reproducible using TiSDK 2.2.0v20120816015712 on the iOS simulator.
I can confirm this bug. But why has it priority "Medium" only?
This issue can't reproduced with TISDK 3.2 or higher. Therefore, marking is resolved.
Ti.File.write(binary) returns true, tested using the above code, hence closing the issue Verified the fix on: Device : iPhone 5s , iOS version : 7.1 SDK: 3.2.2.v20140221161255 CLI version : 3.2.1 OS : MAC OSX 10.9 Alloy: 1.3.1 ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.2.2.201402280732 titanium-code-processor: 1.1.0 XCode : 5.1 Beta 5