Processing potentially large STDIN data, more than once
        Posted  
        
            by d11wtq
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by d11wtq
        
        
        
        Published on 2010-05-29T03:31:39Z
        Indexed on 
            2010/05/29
            3:32 UTC
        
        
        Read the original article
        Hit count: 431
        
I'd like to provide an accessor on a class that provides an NSInputStream for STDIN, which may be several hundred megabytes (or gigabytes, though unlikely, perhaps) of data.
When I caller gets this NSInputStream it should be able to read from it without worrying about exhausting the data it contains. In other words, another block of code may request the NSInputStream and will expect to be able to read from it.
Without first copying all of the data into an NSData object which (I assume) would cause memory exhaustion, what are my options for handling this? The returned NSInputStream does not have to be the same instance, it simply needs to provide the same data.
The best I can come up with right now is to copy STDIN to a temporary file and then return NSInputStream instances using that file. Is this pretty much the only way to handle it? Is there anything I should be cautious of if I go the temporary file route?
© Stack Overflow or respective owner