NSOutputStream write:maxLength: closes stream on zero length

Number:rdar://9930518 Date Originated:10-Aug-2011 01:21 PM
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
10-Aug-2011 01:21 PM Rob Napier:

[outStream write:buffer length:0] will close outStream. This is surprising and undocumented.

Steps to Reproduce:

    NSOutputStream *stream = [NSOutputStream outputStreamToFileAtPath:@"test.out" append:NO];
    [stream open];
    const uint8_t data[5] = "abcde";
    NSCAssert([stream write:data maxLength:5] == 5, @"Test1");
    NSCAssert([stream write:data maxLength:0] == 0, @"Test2");
    NSCAssert([stream write:data maxLength:5] == 5, @"Test3");

Expected Results:

Should succeed with output file containing "abcdeabcde".

Actual Results:

Assertion at Test3 because stream is in state NSStreamStatusAtEnd.




Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!