@@ -26,10 +26,11 @@ #import "OFDictionary.h" #import "OFInflate64Stream.h" #import "OFInflateStream.h" #import "OFSeekableStream.h" #import "OFStream.h" +#import "OFURI.h" #import "OFURIHandler.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @@ -164,10 +165,34 @@ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode { return [[[self alloc] initWithURI: URI mode: mode] autorelease]; } + ++ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive +{ + OFMutableURI *URI = [OFMutableURI URI]; + void *pool = objc_autoreleasePoolPush(); + OFCharacterSet *characterSet = [OFCharacterSet + of_URIPathAllowedCharacterSetWithoutExclamationMark]; + OFString *archiveURI; + + path = [path + stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; + archiveURI = [archive.string + stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; + + URI.scheme = @"of-zip"; + URI.percentEncodedPath = [OFString stringWithFormat: @"%@!%@", + archiveURI, path]; + + [URI makeImmutable]; + + objc_autoreleasePoolPop(pool); + + return URI; +} - (instancetype)init { OF_INVALID_INIT_METHOD }