Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18078] iOS: Ti.Stream.read() doesn't work with Ti.Filesystem.FileStream

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-11-26T22:43:11.000+0000
Affected Version/sRelease 3.4.1
Fix Version/sRelease 3.5.0, Release 4.0.0
ComponentsiOS
Labelsmodule_stream, parity, qe-manualtest
ReporterTony Lukasavage
AssigneeVishal Duggal
Created2014-11-24T13:18:39.000+0000
Updated2014-12-01T18:09:19.000+0000

Description

problem

Using Ti.Stream.read() with an open Ti.Filesystem.FileStream does nothing. The read call never invokes the result callback. Android works fine, but iOS always fails as described above, despite the documentation indicating that both support Ti.Stream.read() on FileStream. Without this support there is no asynchronous way to read files with Titanium on iOS, all reads must be blocking.

test case

var file = Ti.Filesystem.getFile('app.js')
var stream = file.open(Ti.Filesystem.MODE_READ);
var buffer = Ti.createBuffer({length:8096});
Ti.Stream.read(stream, buffer, function(e) {
    Ti.API.error('I never get here');
    Ti.API.error(e);
});

expected

The results callback should return an event object (e) containing all relevant information regarding the read operation. Both Ti.API.error calls should execute and print the results.

actual

The results callback is never executed. Nothing is printed.

Comments

  1. Vishal Duggal 2014-11-24

    Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/6381 3_5_X - https://github.com/appcelerator/titanium_mobile/pull/6382
  2. Khushbu Agrawal 2014-11-26

    [~tlukasavage] I tried to verify this ticket with the above mentioned testcase. It's crashing while opening the file object. Can you please have a look?
  3. Wilson Luu 2014-11-26

    Closing ticket as fixed. Verified Ti.Stream.read() is working i.e. the event object is returned back in the callback. Used the following modified code:
           var file = Ti.Filesystem.getFile('timob18078.txt');
           var stream = file.open(Ti.Filesystem.MODE_READ);
           var buffer = Ti.createBuffer({length:8096});
           
           Ti.Stream.read(stream, buffer, function(e) {
               Ti.API.error('I never get here');
               Ti.API.error(e);
           });
       
    Instead of Ti.Filesystem.getFile('app.js'), created another text file and used Ti.Filesystem.getFile('timob18078.txt'); I think you will not be able to access app.js via Ti.Filesystem.getFile because of security reasons. Tested on: Appcelerator Studio, build: 3.4.1.201410281743 SDK build: 3.5.0.v20141125154115 CLI: 3.4.1 Alloy: 1.5.1 Xcode: 6.1.1 GM Seed Devices: iphone 6 plus (8.1), Samsung Galaxy S4 (4.4.2)
  4. Khushbu Agrawal 2014-11-27

    [~wluu] Thanks for clarifying it.
  5. Tony Lukasavage 2014-11-27

    Yeah, I believe app.js will only work on simulator tests. Thanks for the fix.

JSON Source