Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -854,10 +854,14 @@ 4B90B7A5133AD87D00BD33CB /* OFConnectionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */; }; 4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */; }; 4B91FD12196B4F5900C5C25E /* OFUnknownXMLEntityException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B91FD10196B4F5900C5C25E /* OFUnknownXMLEntityException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B91FD13196B4F5900C5C25E /* OFUnknownXMLEntityException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B91FD11196B4F5900C5C25E /* OFUnknownXMLEntityException.m */; }; + 4B92FDDF1F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B92FDDC1F35DFAC000D541D /* OFMutableZIPArchiveEntry.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B92FDE01F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B92FDDC1F35DFAC000D541D /* OFMutableZIPArchiveEntry.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B92FDE11F35DFBB000D541D /* OFMutableZIPArchiveEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B92FDDD1F35DFAC000D541D /* OFMutableZIPArchiveEntry.m */; }; + 4B92FDE21F35DFBC000D541D /* OFMutableZIPArchiveEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B92FDDD1F35DFAC000D541D /* OFMutableZIPArchiveEntry.m */; }; 4B935D121E9A7DC3001F2957 /* OFSandbox.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B935D101E9A7DC3001F2957 /* OFSandbox.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B935D131E9A7DC3001F2957 /* OFSandbox.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B935D101E9A7DC3001F2957 /* OFSandbox.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B935D141E9A7DC3001F2957 /* OFSandbox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B935D111E9A7DC3001F2957 /* OFSandbox.m */; }; 4B935D151E9A7DC3001F2957 /* OFSandbox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B935D111E9A7DC3001F2957 /* OFSandbox.m */; }; 4B9361A81511000C00DCD16B /* OFThreadPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B9361A61511000C00DCD16B /* OFThreadPool.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1536,10 +1540,12 @@ 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConnectionFailedException.m; path = src/exceptions/OFConnectionFailedException.m; sourceTree = ""; }; 4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFListenFailedException.h; path = src/exceptions/OFListenFailedException.h; sourceTree = ""; }; 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFListenFailedException.m; path = src/exceptions/OFListenFailedException.m; sourceTree = ""; }; 4B91FD10196B4F5900C5C25E /* OFUnknownXMLEntityException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFUnknownXMLEntityException.h; path = src/exceptions/OFUnknownXMLEntityException.h; sourceTree = ""; }; 4B91FD11196B4F5900C5C25E /* OFUnknownXMLEntityException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFUnknownXMLEntityException.m; path = src/exceptions/OFUnknownXMLEntityException.m; sourceTree = ""; }; + 4B92FDDC1F35DFAC000D541D /* OFMutableZIPArchiveEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutableZIPArchiveEntry.h; path = src/OFMutableZIPArchiveEntry.h; sourceTree = ""; }; + 4B92FDDD1F35DFAC000D541D /* OFMutableZIPArchiveEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutableZIPArchiveEntry.m; path = src/OFMutableZIPArchiveEntry.m; sourceTree = ""; }; 4B935D101E9A7DC3001F2957 /* OFSandbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSandbox.h; path = src/OFSandbox.h; sourceTree = ""; }; 4B935D111E9A7DC3001F2957 /* OFSandbox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSandbox.m; path = src/OFSandbox.m; sourceTree = ""; }; 4B9361A61511000C00DCD16B /* OFThreadPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadPool.h; path = src/OFThreadPool.h; sourceTree = ""; }; 4B9361A71511000C00DCD16B /* OFThreadPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadPool.m; path = src/OFThreadPool.m; sourceTree = ""; }; 4B981CDE116F71DD00294DB7 /* OFSeekableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSeekableStream.h; path = src/OFSeekableStream.h; sourceTree = ""; }; @@ -2115,10 +2121,12 @@ 4B6799741099E7C50041064A /* OFMutableString.m */, 4B55254E147AA5DB0003BF47 /* OFMutableString_UTF8.h */, 4B55254F147AA5DB0003BF47 /* OFMutableString_UTF8.m */, 4B4116CD1F21654200E78916 /* OFMutableURL.h */, 4B4116CE1F21654200E78916 /* OFMutableURL.m */, + 4B92FDDC1F35DFAC000D541D /* OFMutableZIPArchiveEntry.h */, + 4B92FDDD1F35DFAC000D541D /* OFMutableZIPArchiveEntry.m */, 4B6743FA163C395900EB1E59 /* OFMutex.h */, 4B6743FB163C395900EB1E59 /* OFMutex.m */, 4B511B7A139C0A34003764A5 /* OFNull.h */, 4B511B7B139C0A34003764A5 /* OFNull.m */, 4B6799751099E7C50041064A /* OFNumber.h */, @@ -2477,10 +2485,11 @@ 4B1223181F23E6C100D9F8FF /* OFMutableData.h in Headers */, 4B2C22011DA292BE00735907 /* OFMutableDictionary.h in Headers */, 4B2C22021DA292BE00735907 /* OFMutableSet.h in Headers */, 4B2C22031DA292BE00735907 /* OFMutableString.h in Headers */, 4B4116D11F21654200E78916 /* OFMutableURL.h in Headers */, + 4B92FDE01F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */, 4B2C22041DA292BE00735907 /* OFMutex.h in Headers */, 4B2C22051DA292BE00735907 /* OFNull.h in Headers */, 4B2C22061DA292BE00735907 /* OFNumber.h in Headers */, 4B2C22071DA292BE00735907 /* OFObject.h in Headers */, 4B2C22081DA292BE00735907 /* OFObject+KeyValueCoding.h in Headers */, @@ -2704,10 +2713,11 @@ 4B1223151F23E6C000D9F8FF /* OFMutableData.h in Headers */, 4B3D23CE1337FCB000DD29B8 /* OFMutableDictionary.h in Headers */, 4B39844713D3AFB400E6F825 /* OFMutableSet.h in Headers */, 4B3D23CF1337FCB000DD29B8 /* OFMutableString.h in Headers */, 4B4116D01F21654200E78916 /* OFMutableURL.h in Headers */, + 4B92FDDF1F35DFB5000D541D /* OFMutableZIPArchiveEntry.h in Headers */, 4B674403163C395900EB1E59 /* OFMutex.h in Headers */, 4B511B7C139C0A34003764A5 /* OFNull.h in Headers */, 4B3D23D01337FCB000DD29B8 /* OFNumber.h in Headers */, 4B3D23D11337FCB000DD29B8 /* OFObject.h in Headers */, 4BC176301D04963000C32718 /* OFObject+KeyValueCoding.h in Headers */, @@ -3268,10 +3278,11 @@ 4B2C214C1DA292BE00735907 /* OFMutableSet.m in Sources */, 4B2C214D1DA292BE00735907 /* OFMutableSet_hashtable.m in Sources */, 4B2C214E1DA292BE00735907 /* OFMutableString.m in Sources */, 4B2C214F1DA292BE00735907 /* OFMutableString_UTF8.m in Sources */, 4B4116D31F21654200E78916 /* OFMutableURL.m in Sources */, + 4B92FDE21F35DFBC000D541D /* OFMutableZIPArchiveEntry.m in Sources */, 4B2C21501DA292BE00735907 /* OFMutex.m in Sources */, 4B2C21511DA292BE00735907 /* OFNull.m in Sources */, 4B2C21521DA292BE00735907 /* OFNumber.m in Sources */, 4B2C21531DA292BE00735907 /* OFObject.m in Sources */, 4B2C21541DA292BE00735907 /* OFObject+Serialization.m in Sources */, @@ -3468,10 +3479,11 @@ 4B39844813D3AFB400E6F825 /* OFMutableSet.m in Sources */, 4BA85BCD140ECCE800E91D51 /* OFMutableSet_hashtable.m in Sources */, 4B3D239D1337FC0D00DD29B8 /* OFMutableString.m in Sources */, 4B552553147AA5DB0003BF47 /* OFMutableString_UTF8.m in Sources */, 4B4116D21F21654200E78916 /* OFMutableURL.m in Sources */, + 4B92FDE11F35DFBB000D541D /* OFMutableZIPArchiveEntry.m in Sources */, 4B674404163C395900EB1E59 /* OFMutex.m in Sources */, 4B511B7D139C0A34003764A5 /* OFNull.m in Sources */, 4B3D239E1337FC0D00DD29B8 /* OFNumber.m in Sources */, 4B3D239F1337FC0D00DD29B8 /* OFObject.m in Sources */, 4BB25E89139C388A00F574EA /* OFObject+Serialization.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -39,10 +39,11 @@ OFMutableData.m \ OFMutableDictionary.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableURL.m \ + OFMutableZIPArchiveEntry.m \ OFNull.m \ OFNumber.m \ OFObject.m \ OFObject+KeyValueCoding.m \ OFObject+Serialization.m \ ADDED src/OFMutableZIPArchiveEntry.h Index: src/OFMutableZIPArchiveEntry.h ================================================================== --- src/OFMutableZIPArchiveEntry.h +++ src/OFMutableZIPArchiveEntry.h @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFZIPArchiveEntry.h" + +OF_ASSUME_NONNULL_BEGIN + +/*! + * @class OFMutableZIPArchiveEntry \ + * OFMutableZIPArchiveEntry.h ObjFW/OFMutableZIPArchiveEntry.h + * + * @brief A class which represents a mutable entry in the central directory of + * a ZIP archive. + */ +@interface OFMutableZIPArchiveEntry: OFZIPArchiveEntry + +/*! + * The file name of the entry. + */ +@property (readwrite, nonatomic, copy) OFString *fileName; + +/*! + * The comment of the entry's file. + */ +@property OF_NULLABLE_PROPERTY (readwrite, nonatomic, copy) + OFString *fileComment; + +/*! + * The extra field of the entry. + */ +@property OF_NULLABLE_PROPERTY (readwrite, nonatomic, copy) OFData *extraField; + +/*! + * The version which made the entry. + * + * The lower 8 bits are the ZIP specification version.@n + * The upper 8 bits are the attribute compatibility. + * See @ref of_zip_archive_entry_attribute_compatibility. + */ +@property (readwrite, nonatomic) uint16_t versionMadeBy; + +/*! + * The minimum version required to extract the file. + * + * The lower 8 bits are the ZIP specification version.@n + * The upper 8 bits are the attribute compatibility. + * See @ref of_zip_archive_entry_attribute_compatibility. + */ +@property (readwrite, nonatomic) uint16_t minVersionNeeded; + +/*! + * The last modification date of the entry's file. + * + * @note Due to limitations of the ZIP format, this has only 2 second precision. + */ +@property (readwrite, nonatomic, retain) OFDate *modificationDate; + +/*! + * The compression method of the entry. + * + * Supported values are: + * Value | Description + * --------------------------------------------------|--------------- + * OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE | No compression + * OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE | Deflate + * OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE64 | Deflate64 + * + * Other values may be returned, but the file cannot be extracted then. + */ +@property (readwrite, nonatomic) uint16_t compressionMethod; + +/*! + * The compressed size of the entry's file. + */ +@property (readwrite, nonatomic) uint64_t compressedSize; + +/*! + * The uncompressed size of the entry's file. + */ +@property (readwrite, nonatomic) uint64_t uncompressedSize; + +/*! + * The CRC32 checksum of the entry's file. + */ +@property (readwrite, nonatomic) uint32_t CRC32; + +/*! + * The version specific attributes. + * + * The meaning of the version specific attributes depends on the attribute + * compatibility part of the version that made the entry. + */ +@property (readwrite, nonatomic) uint32_t versionSpecificAttributes; + +/*! + * The general purpose bit flag of the entry. + * + * See the ZIP specification for details. + */ +@property (readwrite, nonatomic) uint16_t generalPurposeBitFlag; + +/*! + * @brief Converts the OFMutableZIPArchive to an immutable OFZIPArchive. + */ +- (void)makeImmutable; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFMutableZIPArchiveEntry.m Index: src/OFMutableZIPArchiveEntry.m ================================================================== --- src/OFMutableZIPArchiveEntry.m +++ src/OFMutableZIPArchiveEntry.m @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFMutableZIPArchiveEntry.h" +#import "OFString.h" +#import "OFData.h" +#import "OFDate.h" + +@implementation OFMutableZIPArchiveEntry +@dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; +@dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; +@dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; + +- copy +{ + OFMutableZIPArchiveEntry *copy = [self mutableCopy]; + + [copy makeImmutable]; + + return copy; +} + +- (void)setFileName: (OFString *)fileName +{ + OFString *old = _fileName; + _fileName = [fileName copy]; + [old release]; +} + +- (void)setFileComment: (OFString *)fileComment +{ + OFString *old = _fileComment; + _fileComment = [fileComment copy]; + [old release]; +} + +- (void)setExtraField: (OFData *)extraField +{ + OFData *old = _extraField; + _extraField = [extraField copy]; + [old release]; +} + +- (void)setVersionMadeBy: (uint16_t)versionMadeBy +{ + _versionMadeBy = versionMadeBy; +} + +- (void)setMinVersionNeeded: (uint16_t)minVersionNeeded +{ + _minVersionNeeded = minVersionNeeded; +} + +- (void)setModificationDate: (OFDate *)date +{ + void *pool = objc_autoreleasePoolPush(); + + _lastModifiedFileDate = ((([date localYear] - 1980) & 0xFF) << 9) | + (([date localMonthOfYear] & 0x0F) << 5) | + ([date localDayOfMonth] & 0x1F); + _lastModifiedFileTime = (([date localHour] & 0x1F) << 11) | + (([date localMinute] & 0x3F) << 5) | (([date second] >> 1) & 0x0F); + + objc_autoreleasePoolPop(pool); +} + +- (void)setCompressionMethod: (uint16_t)compressionMethod +{ + _compressionMethod = compressionMethod; +} + +- (void)setCompressedSize: (uint64_t)compressedSize +{ + _compressedSize = compressedSize; +} + +- (void)setUncompressedSize: (uint64_t)uncompressedSize +{ + _uncompressedSize = uncompressedSize; +} + +- (void)setCRC32: (uint32_t)CRC32 +{ + _CRC32 = CRC32; +} + +- (void)setVersionSpecificAttributes: (uint32_t)versionSpecificAttributes +{ + _versionSpecificAttributes = versionSpecificAttributes; +} + +- (void)setGeneralPurposeBitFlag: (uint16_t)generalPurposeBitFlag +{ + _generalPurposeBitFlag = generalPurposeBitFlag; +} + +- (void)makeImmutable +{ + object_setClass(self, [OFZIPArchiveEntry class]); +} +@end Index: src/OFZIPArchiveEntry.h ================================================================== --- src/OFZIPArchiveEntry.h +++ src/OFZIPArchiveEntry.h @@ -85,11 +85,11 @@ * @class OFZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents an entry in the central directory of a ZIP * archive. */ -@interface OFZIPArchiveEntry: OFObject +@interface OFZIPArchiveEntry: OFObject { uint16_t _versionMadeBy, _minVersionNeeded, _generalPurposeBitFlag; uint16_t _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; @@ -109,11 +109,16 @@ @property (readonly, nonatomic) OFString *fileName; /*! * The comment of the entry's file. */ -@property (readonly, nonatomic) OFString *fileComment; +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *fileComment; + +/*! + * The extra field of the entry. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFData *extraField; /*! * The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n @@ -129,10 +134,17 @@ * The upper 8 bits are the attribute compatibility. * See @ref of_zip_archive_entry_attribute_compatibility. */ @property (readonly, nonatomic) uint16_t minVersionNeeded; +/*! + * The last modification date of the entry's file. + * + * @note Due to limitations of the ZIP format, this has only 2 second precision. + */ +@property (readonly, nonatomic) OFDate *modificationDate; + /*! * The compression method of the entry. * * Supported values are: * Value | Description @@ -173,25 +185,28 @@ * * 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; + - init OF_UNAVAILABLE; /*! - * @brief Returns the last modification date of the entry's file. - * - * @return The last modification date of the entry's file - */ -- (OFDate *)modificationDate; - -/*! - * @brief Returns the extra field of the entry. - * - * @return The extra field of the entry - */ -- (OFData *)extraField; + * @brief Initializes an already allocated OFZIPArchiveEntry with the specified + * file name. + * + * @param fileName The file name for the OFZIPArchiveEntry + * @return An initialized OFZIPArchiveEntry + */ +- initWithFileName: (OFString *)fileName; @end #ifdef __cplusplus extern "C" { #endif @@ -219,5 +234,7 @@ #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END + +#import "OFMutableZIPArchiveEntry.h" Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -140,27 +140,33 @@ *data = NULL; *size = 0; } @implementation OFZIPArchiveEntry -@synthesize fileName = _fileName, fileComment = _fileComment; -@synthesize versionMadeBy = _versionMadeBy; -@synthesize minVersionNeeded = _minVersionNeeded; -@synthesize compressionMethod = _compressionMethod; -@synthesize compressedSize = _compressedSize; -@synthesize uncompressedSize = _uncompressedSize; -@synthesize CRC32 = _CRC32; -@synthesize versionSpecificAttributes = _versionSpecificAttributes; -@synthesize generalPurposeBitFlag = _generalPurposeBitFlag; -@synthesize of_lastModifiedFileTime = _lastModifiedFileTime; -@synthesize of_lastModifiedFileDate = _lastModifiedFileDate; -@synthesize of_localFileHeaderOffset = _localFileHeaderOffset; ++ (instancetype)entryWithFileName: (OFString *)fileName +{ + return [[[self alloc] initWithFileName: fileName] autorelease]; +} - init { OF_INVALID_INIT_METHOD } + +- initWithFileName: (OFString *)fileName +{ + self = [super init]; + + @try { + _fileName = [_fileName copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (instancetype)of_initWithStream: (OFStream *)stream { self = [super init]; @@ -195,14 +201,17 @@ ? OF_STRING_ENCODING_UTF_8 : OF_STRING_ENCODING_CODEPAGE_437); _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; - _extraField = - [[stream readDataWithCount: extraFieldLength] copy]; - _fileComment = [[stream readStringWithLength: fileCommentLength - encoding: encoding] copy]; + if (extraFieldLength > 0) + _extraField = + [[stream readDataWithCount: extraFieldLength] copy]; + if (fileCommentLength > 0) + _fileComment = [[stream + readStringWithLength: fileCommentLength + encoding: encoding] copy]; of_zip_archive_entry_extra_field_find(_extraField, OF_ZIP_ARCHIVE_ENTRY_EXTRA_FIELD_ZIP64, &ZIP64, &ZIP64Size); if (ZIP64 != NULL) { @@ -239,10 +248,67 @@ [_extraField release]; [_fileComment release]; [super dealloc]; } + +- copy +{ + return [self retain]; +} + +- mutableCopy +{ + OFZIPArchiveEntry *copy = + [[OFMutableZIPArchiveEntry alloc] initWithFileName: _fileName]; + + @try { + copy->_versionMadeBy = _versionMadeBy; + copy->_minVersionNeeded = _minVersionNeeded; + copy->_generalPurposeBitFlag = _generalPurposeBitFlag; + copy->_compressionMethod = _compressionMethod; + copy->_lastModifiedFileTime = _lastModifiedFileTime; + copy->_lastModifiedFileDate = _lastModifiedFileDate; + copy->_CRC32 = _CRC32; + copy->_compressedSize = _compressedSize; + copy->_uncompressedSize = _uncompressedSize; + copy->_extraField = [_extraField copy]; + copy->_fileComment = [_extraField copy]; + copy->_startDiskNumber = _startDiskNumber; + copy->_internalAttributes = _internalAttributes; + copy->_versionSpecificAttributes = _versionSpecificAttributes; + copy->_localFileHeaderOffset = _localFileHeaderOffset; + } @catch (id e) { + [copy release]; + @throw e; + } +} + +- (OFString *)fileName +{ + return _fileName; +} + +- (OFString *)fileComment +{ + return _fileComment; +} + +- (OFData *)extraField +{ + return _extraField; +} + +- (uint16_t)versionMadeBy +{ + return _versionMadeBy; +} + +- (uint16_t)minVersionNeeded +{ + return _minVersionNeeded; +} - (OFDate *)modificationDate { void *pool = objc_autoreleasePoolPush(); uint16_t year = ((_lastModifiedFileDate & 0xFE00) >> 9) + 1980; @@ -264,13 +330,53 @@ objc_autoreleasePoolPop(pool); return [date autorelease]; } -- (OFData *)extraField +- (uint16_t)compressionMethod +{ + return _compressionMethod; +} + +- (uint64_t)compressedSize +{ + return _compressedSize; +} + +- (uint64_t)uncompressedSize +{ + return _uncompressedSize; +} + +- (uint32_t)CRC32 +{ + return _CRC32; +} + +- (uint32_t)versionSpecificAttributes +{ + return _versionSpecificAttributes; +} + +- (uint16_t)generalPurposeBitFlag +{ + return _generalPurposeBitFlag; +} + +- (uint16_t)of_lastModifiedFileTime +{ + return _lastModifiedFileTime; +} + +- (uint16_t)of_lastModifiedFileDate +{ + return _lastModifiedFileDate; +} + +- (int64_t)of_localFileHeaderOffset { - return [[_extraField copy] autorelease]; + return _localFileHeaderOffset; } - (OFString *)description { void *pool = objc_autoreleasePoolPush();