@@ -17,12 +17,13 @@ /** * \brief A base class for different types of streams. */ @interface OFStream: OFObject { - char *cache; - size_t cache_len; + char *cache, *wcache; + size_t cache_len, wcache_len; + BOOL use_wcache; } /** * Returns a boolean whether the end of the stream has been reached. * @@ -168,20 +169,47 @@ * stream has been reached. */ - (OFString*)readTillDelimiter: (OFString*)delimiter withEncoding: (enum of_string_encoding)encoding; +/** + * Caches all writes until flushWriteCache is called. + */ +- cacheWrites; + +/** + * Writes everything in the write cache to the stream. + */ +- flushWriteCache; + /** * Writes from a buffer into the stream. + * + * IMPORTANT: Do *NOT* override this in subclasses! Override + * writeNBytesWithoutCache:fromBuffer: instead, as otherwise, you *WILL* break + * caching and thus get broken results! * * \param buf The buffer from which the data is written to the stream * \param size The size of the data that should be written * \return The number of bytes written */ - (size_t)writeNBytes: (size_t)size fromBuffer: (const char*)buf; +/** + * Directly writes from a buffer into the stream without caching the data first. + * + * IMPORTANT: Do *NOT* use this! Use writeNBytes:fromBuffer: instead, as this is + * *ONLY* for being overriden in subclasses! + * + * \param buf The buffer from which the data is written to the stream + * \param size The size of the data that should be written + * \return The number of bytes written + */ +- (size_t)writeNBytesWithoutCache: (size_t)size + fromBuffer: (const char*)buf; + /** * Writes an uint8_t into the stream. * * \param int8 An uint8_t */