Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7996] Ti API: Stream.writeStream--different handling for end of stream

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-15T18:30:25.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sn/a
ComponentsTiAPI
Labelsparity
ReporterArthur Evans
AssigneeEric Merriman
Created2012-03-14T11:14:06.000+0000
Updated2017-06-15T18:30:25.000+0000

Description

If writeStream(inputStream, outputStream, chunkSize, callback) is invoked when the input stream is at end of stream, behavior varies by platform. Neither platform appears to follow the spec. From my reading of the spec, it's not clear what's supposed to happen. For the pump callback it specifically says that the bytesProcessed property in the callback arg is set to -1 on end of stream. On iOS, an exception is thrown, so the callback isn't invoked. On Android, bytesProcessed is set to 0 in the callback, errorState is 0, and errorDescription is "". It seems like it would be more consistent with other functionality if bytesProcessed reported -1 in both cases. Same behavior holds for the synchronous version of the method--returns 0 on Android, throws an exception on iOS. If we regard passing an empty stream (or a stream at EOF) as an error, we should treat it as an error on both platforms. Testcase:
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
win1.open();

var stream1 = Ti.Stream.createStream({ 
	source: Ti.createBuffer({ length: 0}),
	mode: Ti.Stream.MODE_READ
});

var stream2 = Ti.Stream.createStream({ 
	source: Ti.createBuffer({ length: 1024}),
	mode: Ti.Stream.MODE_READ
});

Ti.Stream.writeStream(stream1, stream2, 1024, function(arg) {
	Ti.API.info("bytes processed: " + arg.bytesProcessed);
	Ti.API.info("Event: " + JSON.stringify(arg, false, 2));
});
Please clarify expected behavior.

Comments

  1. Lee Morris 2017-06-15

    Closing ticket due to time passed and lack of progress in the past few years. Any problems, please file a new ticket.

JSON Source