{ "id": "62367", "key": "TIMOB-1735", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2017-06-21T21:58:20.000+0000", "created": "2011-04-15T03:00:53.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "api" ], "versions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-06-21T21:58:20.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

The File.read method is documented to \"return the contents of\r\nfile as blob\":

\r\n

\r\nhttps://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Fi...

\r\n

It seems like a reasonable expectation that the returned blob\r\nactually contains the data read from the file, however this doesn't\r\nappear to be the case; we seem to end up with some sort of indirect\r\nreference to the file instead!

\r\n

If the file is subsequently deleted or altered, our blob also\r\nmagically empties or changes, contrary to expectations.

\r\n

Here's some sample code to create a file, read its contents,\r\nthen delete it. Before deleting it our blob contains the expected\r\namount of data; afterwards its contents appear to have disappeared.\r\n(Note that we have to check both .size and .length properties\r\nbecause the undocumented Ti.Blob type has inconsistent APIs between\r\nAndroid and iPhone implementations.)

\r\n
\r\n// Create a temporary file and return its pathname\r\nfunction buildFile() {\r\n    //var tempFile = Ti.Filesystem.createTempFile();\r\n    var tempFile = Ti.Filesystem.getFile(\r\n        Ti.Filesystem.applicationDataDirectory + '/myfile');\r\n    tempFile.write(\"Hello I am a temp file\");\r\n    return tempFile.nativePath;\r\n}\r\n\r\n// Read the given file's contents into a blob\r\nfunction readFile(path) {\r\n    return Ti.Filesystem.getFile(path).read();\r\n}\r\n\r\nfunction deleteFile(path) {\r\n    return Ti.Filesystem.getFile(path).deleteFile();\r\n}\r\n\r\n// Create a temporary file and read it in\r\nvar path = buildFile();\r\nTi.API.info(\"Created temp file \" + path);\r\n\r\nvar blob = readFile(path);\r\nTi.API.info(\"We got a blob! It's \" + (blob.length || blob.size) + \" bytes long\");\r\n\r\n// We no longer need the temporary file!\r\nTi.API.info(\"Deleting \" + path);\r\ndeleteFile(path);\r\n\r\nTi.API.info(\"Now our blob is \" + (blob.length || blob.size) + \" bytes long\");\r\n
\r\n

Android:

\r\n
\r\n[INFO] [779,976] Created temp file file:///data/data/net.status.client.quicktest/app_appdata/myfile\r\n[INFO] [290,1266] We got a blob! It's 22 bytes long\r\n[INFO] [2,1268] Deleting file:///data/data/net.status.client.quicktest/app_appdata/myfile\r\n[INFO] [81,1349] Now our blob is null bytes long\r\n
\r\n

iPhone:

\r\n
\r\n[INFO] Created temp file /Users/brion/Library/Application Support/iPhone Simulator/4.0.2/Applications/74ED2286-A5A1-45AF-902F-4FFF2DABFD72/Documents/myfile\r\n[INFO] We got a blob! It's 22 bytes long\r\n[INFO] Deleting /Users/brion/Library/Application Support/iPhone Simulator/4.0.2/Applications/74ED2286-A5A1-45AF-902F-4FFF2DABFD72/Documents/myfile\r\n[INFO] Now our blob is 0 bytes long\r\n
\r\n

If this is intended behavior, it needs to be documented in the\r\ndocs for File.read; it also should be documented in the docs for\r\nthe Ti.Blob type (which is conspicuously absent at this time).\r\nThere also needs to be a clear way added to actually read\r\nthe current contents of a file, independent of the file's continued\r\nexistence or contents...

\r\n

Assigning to our support contact. (Nolan, is there anyone\r\nspecific we should be assigning bugs in the filesystem area to?\r\nThanks!)

\r\n

Related issues:

\r\n

lack of docs for Ti.Blob: \r\nhttps://appcelerator.lighthouseapp.com/projects/32238/tickets/1580-...

\r\n

inconsistent API for Ti.Blob size/length: \r\nhttps://appcelerator.lighthouseapp.com/projects/32238/tickets/1656-...

{html}", "attachment": [], "flagged": false, "summary": "iOS: Blob data returned from File.read becomes empty when the file is deleted", "creator": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "126500", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Known filesystem issue. This is a dupe of something but not sure\nwhat.

{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:00:54.000+0000", "updated": "2011-04-15T03:00:54.000+0000" }, { "id": "209494", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Validated against SDK 2.2.0.014b86f. A consequence of file blobs not being stored in memory.", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-07-25T17:46:46.000+0000", "updated": "2012-07-25T17:46:46.000+0000" }, { "id": "422513", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket due to time passed and lack of progress for a number of years. Any problems, please file a new ticket.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-06-21T21:58:20.000+0000", "updated": "2017-06-21T21:58:20.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }