Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -14,10 +14,11 @@ #import "OFXMLAttribute.h" @class OFXMLParser; @class OFArray; @class OFMutableArray; +@class OFStream; #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) typedef void (^of_xml_parser_processing_instructions_block_t)( OFXMLParser *parser, OFString *pi); typedef void (^of_xml_parser_element_start_block_t)(OFXMLParser *parser, @@ -300,10 +301,17 @@ * * \param str The string to parse */ - (void)parseString: (OFString*)str; +/** + * Parses the specified stream. + * + * \param stream The stream to parse + */ +- (void)parseStream: (OFStream*)stream; + /** * Parses the specified file. * * \param path The path to the file to parse */ Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -17,10 +17,11 @@ #import "OFXMLParser.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFXMLAttribute.h" +#import "OFStream.h" #import "OFFile.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" @@ -206,31 +207,35 @@ - (void)parseString: (OFString*)str { [self parseBuffer: [str cString] withSize: [str cStringLength]]; } + +- (void)parseStream: (OFStream*)stream +{ + char *buf = [self allocMemoryWithSize: of_pagesize]; + + @try { + while (![stream isAtEndOfStream]) { + size_t len = [stream readNBytes: of_pagesize + intoBuffer: buf]; + + [self parseBuffer: buf + withSize: len]; + } + } @finally { + [self freeMemory: buf]; + } +} - (void)parseFile: (OFString*)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @try { - char *buf = [self allocMemoryWithSize: of_pagesize]; - - @try { - while (![file isAtEndOfStream]) { - size_t size; - - size = [file readNBytes: of_pagesize - intoBuffer: buf]; - [self parseBuffer: buf - withSize: size]; - } - } @finally { - [self freeMemory: buf]; - } + [self parseStream: file]; } @finally { [file release]; } }