@@ -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]; } }