Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -10,10 +10,11 @@ */ #import "OFObject.h" @class OFString; +@class OFDataArray; /** * \brief A base class for different types of streams. */ @interface OFStream: OFObject @@ -71,10 +72,16 @@ * \return The number of bytes read */ - (size_t)readNBytesWithoutCache: (size_t)size intoBuffer: (char*)buf; +/** + * \return An OFDataArray with an item size of 1 with all the data of the + * stream until the end of the stream is reached. + */ +- (OFDataArray*)readDataArrayTillEndOfStream; + /** * Read until a newline, \\0 or end of stream occurs. * * \return The line that was read, autoreleased, or nil if the end of the * stream has been reached. Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -14,10 +14,11 @@ #include #include #import "OFStream.h" #import "OFString.h" +#import "OFDataArray.h" #import "OFExceptions.h" #import "macros.h" @implementation OFStream - init @@ -81,10 +82,34 @@ intoBuffer: (char*)buf { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } + +- (OFDataArray*)readDataArrayTillEndOfStream +{ + OFDataArray *a; + char *buf; + + a = [OFDataArray dataArrayWithItemSize: 1]; + buf = [self allocMemoryWithSize: of_pagesize]; + + @try { + while (![self atEndOfStream]) { + size_t size; + + size = [self readNBytes: of_pagesize + intoBuffer: buf]; + [a addNItems: size + fromCArray: buf]; + } + } @finally { + [self freeMemory: buf]; + } + + return a; +} - (OFString*)readLine { return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; }