Index: src/OFLHAArchiveEntry+Private.h ================================================================== --- src/OFLHAArchiveEntry+Private.h +++ src/OFLHAArchiveEntry+Private.h @@ -17,14 +17,15 @@ OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFLHAArchiveEntry () +- (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (char [_Nonnull 21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init); - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END Index: src/OFLHAArchiveEntry.h ================================================================== --- src/OFLHAArchiveEntry.h +++ src/OFLHAArchiveEntry.h @@ -125,28 +125,11 @@ /** * @brief The LHA extensions of the file. */ @property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; -/** - * @brief Creates a new OFLHAArchiveEntry with the specified file name. - * - * @param fileName The file name for the OFLHAArchiveEntry - * @return A new, autoreleased OFLHAArchiveEntry - */ -+ (instancetype)entryWithFileName: (OFString *)fileName; - - (instancetype)init OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFLHAArchiveEntry with the specified - * file name. - * - * @param fileName The file name for the OFLHAArchiveEntry - * @return An initialized OFLHAArchiveEntry - */ -- (instancetype)initWithFileName: (OFString *)fileName; @end OF_ASSUME_NONNULL_END #import "OFMutableLHAArchiveEntry.h" Index: src/OFLHAArchiveEntry.m ================================================================== --- src/OFLHAArchiveEntry.m +++ src/OFLHAArchiveEntry.m @@ -301,26 +301,20 @@ *fileNameLength = length - pos; *directoryName = cString; *directoryNameLength = pos; } -+ (instancetype)entryWithFileName: (OFString *)fileName -{ - return [[[self alloc] initWithFileName: fileName] autorelease]; -} - - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)initWithFileName: (OFString *)fileName +- (instancetype)of_init { self = [super init]; @try { - _fileName = [fileName copy]; _compressionMethod = @"-lh0-"; _date = [[OFDate alloc] initWithTimeIntervalSince1970: 0]; } @catch (id e) { [self release]; @throw e; Index: src/OFMutableLHAArchiveEntry.h ================================================================== --- src/OFMutableLHAArchiveEntry.h +++ src/OFMutableLHAArchiveEntry.h @@ -108,13 +108,30 @@ /** * @brief The LHA extensions of the file. */ @property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; +/** + * @brief Creates a new OFMutableLHAArchiveEntry with the specified file name. + * + * @param fileName The file name for the OFLHAArchiveEntry + * @return A new, autoreleased OFLHAArchiveEntry + */ ++ (instancetype)entryWithFileName: (OFString *)fileName; + +/** + * @brief Initializes an already allocated OFMutableLHAArchiveEntry with the + * specified file name. + * + * @param fileName The file name for the OFLHAArchiveEntry + * @return An initialized OFLHAArchiveEntry + */ +- (instancetype)initWithFileName: (OFString *)fileName; + /** * @brief Converts the OFMutableLHAArchiveEntry to an immutable * OFLHAArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END Index: src/OFMutableLHAArchiveEntry.m ================================================================== --- src/OFMutableLHAArchiveEntry.m +++ src/OFMutableLHAArchiveEntry.m @@ -14,10 +14,11 @@ */ #include "config.h" #import "OFMutableLHAArchiveEntry.h" +#import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" @@ -25,10 +26,29 @@ @implementation OFMutableLHAArchiveEntry @dynamic fileName, compressionMethod, compressedSize, uncompressedSize, date; @dynamic headerLevel, CRC16, operatingSystemIdentifier, fileComment, mode, UID; @dynamic GID, owner, group, modificationDate, extensions; + ++ (instancetype)entryWithFileName: (OFString *)fileName +{ + return [[[self alloc] initWithFileName: fileName] autorelease]; +} + +- (instancetype)initWithFileName: (OFString *)fileName +{ + self = [super of_init]; + + @try { + _fileName = [fileName copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (id)copy { OFMutableLHAArchiveEntry *copy = [self mutableCopy]; Index: src/OFMutableTarArchiveEntry.h ================================================================== --- src/OFMutableTarArchiveEntry.h +++ src/OFMutableTarArchiveEntry.h @@ -89,13 +89,30 @@ /** * @brief The device major (if the file is a device). */ @property (readwrite, nonatomic) unsigned long deviceMinor; +/** + * @brief Creates a new OFMutableTarArchiveEntry with the specified file name. + * + * @param fileName The file name for the OFTarArchiveEntry + * @return A new, autoreleased OFTarArchiveEntry + */ ++ (instancetype)entryWithFileName: (OFString *)fileName; + +/** + * @brief Initializes an already allocated OFMutableTarArchiveEntry with the + * specified file name. + * + * @param fileName The file name for the OFTarArchiveEntry + * @return An initialized OFTarArchiveEntry + */ +- (instancetype)initWithFileName: (OFString *)fileName; + /** * @brief Converts the OFMutableTarArchiveEntry to an immutable * OFTarArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END Index: src/OFMutableTarArchiveEntry.m ================================================================== --- src/OFMutableTarArchiveEntry.m +++ src/OFMutableTarArchiveEntry.m @@ -14,16 +14,36 @@ */ #include "config.h" #import "OFMutableTarArchiveEntry.h" +#import "OFTarArchiveEntry+Private.h" #import "OFString.h" #import "OFDate.h" @implementation OFMutableTarArchiveEntry @dynamic fileName, mode, UID, GID, size, modificationDate, type, targetFileName; @dynamic owner, group, deviceMajor, deviceMinor; + ++ (instancetype)entryWithFileName: (OFString *)fileName +{ + return [[[self alloc] initWithFileName: fileName] autorelease]; +} + +- (instancetype)initWithFileName: (OFString *)fileName +{ + self = [super of_init]; + + @try { + _fileName = [fileName copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (id)copy { OFMutableTarArchiveEntry *copy = [self mutableCopy]; Index: src/OFMutableZIPArchiveEntry.h ================================================================== --- src/OFMutableZIPArchiveEntry.h +++ src/OFMutableZIPArchiveEntry.h @@ -117,13 +117,30 @@ * * See the ZIP specification for details. */ @property (readwrite, nonatomic) uint16_t generalPurposeBitFlag; +/** + * @brief Creates a new OFMutableZIPArchiveEntry with the specified file name. + * + * @param fileName The file name for the OFZIPArchiveEntry + * @return A new, autoreleased OFZIPArchiveEntry + */ ++ (instancetype)entryWithFileName: (OFString *)fileName; + +/** + * @brief Initializes an already allocated OFMutableZIPArchiveEntry with the + * specified file name. + * + * @param fileName The file name for the OFZIPArchiveEntry + * @return An initialized OFZIPArchiveEntry + */ +- (instancetype)initWithFileName: (OFString *)fileName; + /** * @brief Converts the OFMutableZIPArchiveEntry to an immutable * OFZIPArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END Index: src/OFMutableZIPArchiveEntry.m ================================================================== --- src/OFMutableZIPArchiveEntry.m +++ src/OFMutableZIPArchiveEntry.m @@ -27,10 +27,36 @@ @implementation OFMutableZIPArchiveEntry @dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; + ++ (instancetype)entryWithFileName: (OFString *)fileName +{ + return [[[self alloc] initWithFileName: fileName] autorelease]; +} + +- (instancetype)initWithFileName: (OFString *)fileName +{ + self = [super of_init]; + + @try { + void *pool = objc_autoreleasePoolPush(); + + if (fileName.UTF8StringLength > UINT16_MAX) + @throw [OFOutOfRangeException exception]; + + _fileName = [fileName copy]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; Index: src/OFTarArchiveEntry+Private.h ================================================================== --- src/OFTarArchiveEntry+Private.h +++ src/OFTarArchiveEntry+Private.h @@ -20,13 +20,14 @@ @class OFStream; OF_DIRECT_MEMBERS @interface OFTarArchiveEntry () +- (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init); - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END Index: src/OFTarArchiveEntry.h ================================================================== --- src/OFTarArchiveEntry.h +++ src/OFTarArchiveEntry.h @@ -123,28 +123,11 @@ /** * @brief The device major (if the file is a device). */ @property (readonly, nonatomic) unsigned long deviceMinor; -/** - * @brief Creates a new OFTarArchiveEntry with the specified file name. - * - * @param fileName The file name for the OFTarArchiveEntry - * @return A new, autoreleased OFTarArchiveEntry - */ -+ (instancetype)entryWithFileName: (OFString *)fileName; - - (instancetype)init OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFTarArchiveEntry with the specified - * file name. - * - * @param fileName The file name for the OFTarArchiveEntry - * @return An initialized OFTarArchiveEntry - */ -- (instancetype)initWithFileName: (OFString *)fileName; @end OF_ASSUME_NONNULL_END #import "OFMutableTarArchiveEntry.h" Index: src/OFTarArchiveEntry.m ================================================================== --- src/OFTarArchiveEntry.m +++ src/OFTarArchiveEntry.m @@ -72,19 +72,24 @@ return value; } @implementation OFTarArchiveEntry -+ (instancetype)entryWithFileName: (OFString *)fileName -{ - return [[[self alloc] initWithFileName: fileName] autorelease]; -} - - (instancetype)init { OF_INVALID_INIT_METHOD } + +- (instancetype)of_init +{ + self = [super init]; + + _type = OFTarArchiveEntryTypeFile; + _mode = 0644; + + return self; +} - (instancetype)of_initWithHeader: (unsigned char [512])header encoding: (OFStringEncoding)encoding { self = [super init]; @@ -137,26 +142,10 @@ _fileName = [fileName copy]; } } objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithFileName: (OFString *)fileName -{ - self = [super init]; - - @try { - _fileName = [fileName copy]; - _type = OFTarArchiveEntryTypeFile; - _mode = 0644; } @catch (id e) { [self release]; @throw e; } Index: src/OFZIPArchiveEntry+Private.h ================================================================== --- src/OFZIPArchiveEntry+Private.h +++ src/OFZIPArchiveEntry+Private.h @@ -20,10 +20,11 @@ @interface OFZIPArchiveEntry () @property (readonly, nonatomic) uint16_t of_lastModifiedFileTime, of_lastModifiedFileDate; @property (readonly, nonatomic) int64_t of_localFileHeaderOffset; +- (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init) OF_DIRECT; - (uint64_t)of_writeToStream: (OFStream *)stream OF_DIRECT; @end Index: src/OFZIPArchiveEntry.h ================================================================== --- src/OFZIPArchiveEntry.h +++ src/OFZIPArchiveEntry.h @@ -207,28 +207,11 @@ * * See the ZIP specification for details. */ @property (readonly, nonatomic) uint16_t generalPurposeBitFlag; -/** - * @brief Creates a new OFZIPArchiveEntry with the specified file name. - * - * @param fileName The file name for the OFZIPArchiveEntry - * @return A new, autoreleased OFZIPArchiveEntry - */ -+ (instancetype)entryWithFileName: (OFString *)fileName; - - (instancetype)init OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated OFZIPArchiveEntry with the specified - * file name. - * - * @param fileName The file name for the OFZIPArchiveEntry - * @return An initialized OFZIPArchiveEntry - */ -- (instancetype)initWithFileName: (OFString *)fileName; @end #ifdef __cplusplus extern "C" { #endif Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -170,39 +170,18 @@ *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry -+ (instancetype)entryWithFileName: (OFString *)fileName -{ - return [[[self alloc] initWithFileName: fileName] autorelease]; -} - - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)initWithFileName: (OFString *)fileName -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (fileName.UTF8StringLength > UINT16_MAX) - @throw [OFOutOfRangeException exception]; - - _fileName = [fileName copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; +- (instancetype)of_init +{ + return [super init]; } - (instancetype)of_initWithStream: (OFStream *)stream { self = [super init];