Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -49,11 +49,12 @@ /*! * @brief Creates a new OFFile with the specified path and mode. * * @param path The path to the file to open as a string - * @param mode The mode in which the file should be opened.@n + * @param mode The mode in which the file should be opened. + * @n * Possible modes are: * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write Index: src/OFURLHandler.h ================================================================== --- src/OFURLHandler.h +++ src/OFURLHandler.h @@ -66,10 +66,34 @@ * @param scheme The scheme to initialize for * @return An initialized URL handler */ - (instancetype)initWithScheme: (OFString *)scheme OF_DESIGNATED_INITIALIZER; +/*! + * @brief Opens the item at the specified URL. + * + * @param URL The URL of the item which should be opened + * @param mode The mode in which the file should be opened.@n + * Possible modes are: + * @n + * Mode | Description + * ---------------|------------------------------------- + * `r` | Read-only + * `r+` | Read-write + * `w` | Write-only, create or truncate + * `wx` | Write-only, create or fail, exclusive + * `w+` | Read-write, create or truncate + * `w+x` | Read-write, create or fail, exclusive + * `a` | Write-only, create or append + * `a+` | Read-write, create or append + * @n + * The handler is allowed to not implement all modes and is also + * allowed to implement additional, scheme-specific modes. + */ +- (OFStream *)openItemAtURL: (OFURL *)URL + mode: (OFString *)mode; + /*! * @brief Returns the attributes for the item at the specified URL. * * @param URL The URL to return the attributes for * @return A dictionary of attributes for the specified URL, with the keys of Index: src/OFURLHandler.m ================================================================== --- src/OFURLHandler.m +++ src/OFURLHandler.m @@ -116,10 +116,16 @@ { [_scheme release]; [super dealloc]; } + +- (OFStream *)openItemAtURL: (OFURL *)URL + mode: (OFString *)mode +{ + OF_UNRECOGNIZED_SELECTOR +} - (of_file_attributes_t)attributesOfItemAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } Index: src/OFURLHandler_file.m ================================================================== --- src/OFURLHandler_file.m +++ src/OFURLHandler_file.m @@ -410,10 +410,23 @@ if (of_stat(path, &s) == -1) return false; return S_ISDIR(s.st_mode); } + +- (OFStream *)openItemAtURL: (OFURL *)URL + mode: (OFString *)mode +{ + void *pool = objc_autoreleasePoolPush(); + OFFile *file = [[OFFile alloc] + initWithPath: [URL fileSystemRepresentation] + mode: mode]; + + objc_autoreleasePoolPop(pool); + + return [file autorelease]; +} - (of_file_attributes_t)attributesOfItemAtURL: (OFURL *)URL { of_mutable_file_attributes_t ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -45,10 +45,11 @@ #import "OFIntrospection.h" #import "OFNumber.h" #import "OFDate.h" #import "OFURL.h" +#import "OFURLHandler.h" #import "OFStream.h" #import "OFStdIOStream.h" #import "OFInflateStream.h" #import "OFInflate64Stream.h"