Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -84,10 +84,20 @@ * \param size The size of the data that should be read. * The buffer MUST be EXACTLY this big! */ - (void)readExactlyNBytes: (size_t)size intoBuffer: (char*)buf; +/** + * Reads nitems items with the specified item size from the stream and returns + * them in an OFDataArray. + * + * \param itemsize The size of each item + * \param nitems The number of iteams to read + * \return An OFDataArray with at nitems items. + */ +- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize + andNItems: (size_t)nitems; /** * \return An OFDataArray with an item size of 1 with all the data of the * stream until the end of the stream is reached. */ Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -99,10 +99,33 @@ while (len < size) len += [self readNBytes: size - len intoBuffer: buf + len]; } + +- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize + andNItems: (size_t)nitems +{ + OFDataArray *da; + char *tmp; + + da = [OFDataArray dataArrayWithItemSize: itemsize]; + tmp = [self allocMemoryForNItems: nitems + withSize: itemsize]; + + @try { + [self readExactlyNBytes: nitems * itemsize + intoBuffer: tmp]; + + [da addNItems: nitems + fromCArray: tmp]; + } @finally { + [self freeMemory: tmp]; + } + + return da; +} - (OFDataArray*)readDataArrayTillEndOfStream { OFDataArray *a; char *buf;