ObjFW  Check-in [fee2316eca]

Overview
Comment:OF{LHA,Tar,ZIP}Archive: Use URL instead of path
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fee2316eca9229a7f0e8a9f7fde65b3aa5480f739fa9f3c42b490f15323095af
User & Date: js on 2022-08-15 23:02:10
Other Links: manifest | tags
Context
2022-08-15
23:38
Consistently use sed -e for multiple scripts check-in: e817fac245 user: js tags: trunk
23:02
OF{LHA,Tar,ZIP}Archive: Use URL instead of path check-in: fee2316eca user: js tags: trunk
2022-08-13
14:33
OFTCPSocket: Minor documentation fix check-in: 08cb210f76 user: js tags: trunk
Changes

Modified src/OFLHAArchive.h from [eaf15d177e] to [0ac8f473ff].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+







#import "OFKernelEventObserver.h"
#import "OFLHAArchiveEntry.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@class OFStream;
@class OFURL;

/**
 * @class OFLHAArchive OFLHAArchive.h ObjFW/OFLHAArchive.h
 *
 * @brief A class for accessing and manipulating LHA files.
 */
OF_SUBCLASSING_RESTRICTED
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106

107
108
109
110
111
112
113
114
60
61
62
63
64
65
66

67
68
69

70
71
72
73
74
75

76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97

98
99
100
101
102
103

104

105
106
107
108
109
110
111







-



-
+





-
+
-

















-




-
+





-
+
-







 * @param mode The mode for the LHA file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFLHAArchive
 */
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFLHAArchive object with the specified file.
 *
 * @param path The path to the LHA file
 * @param URL The URL to the LHA file
 * @param mode The mode for the LHA file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFLHAArchive
 */
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode;
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFLHAArchive object with the
 *	  specified stream.
 *
 * @param stream A stream from which the LHA archive will be read.
 *		 For read and append mode, this needs to be an OFSeekableStream.
 * @param mode The mode for the LHA file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFLHAArchive
 */
- (instancetype)initWithStream: (OFStream *)stream
			  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFLHAArchive object with the
 *	  specified file.
 *
 * @param path The path to the LHA file
 * @param URL The URL to the LHA file
 * @param mode The mode for the LHA file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFLHAArchive
 */
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

/**
 * @brief Returns the next entry from the LHA archive or `nil` if all entries
 *	  have been read.
 *
 * @note This is only available in read mode.
 *

Modified src/OFLHAArchive.m from [5dc375ab00] to [3c453bb2f0].

17
18
19
20
21
22
23
24
25
26
27
28
29


30

31
32
33
34
35
36
37
17
18
19
20
21
22
23



24


25
26
27
28
29
30
31
32
33
34
35







-
-
-

-
-
+
+

+








#include <errno.h>

#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFLHAArchiveEntry+Private.h"
#import "OFCRC16.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFLHADecompressingStream.h"
#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFURLHandler.h"

#import "OFChecksumMismatchException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
78
79
80
81
82
83
84
85
86

87
88

89
90
91
92
93
94
95
96
97
76
77
78
79
80
81
82


83
84

85
86

87
88
89
90
91
92
93







-
-
+

-
+

-







@synthesize encoding = _encoding;

+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode
{
	return [[[self alloc] initWithStream: stream mode: mode] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURL: URL mode: mode] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode
123
124
125
126
127
128
129
130
131

132

133

134

135
136
137



138
139
140
141







142
143
144


145
146
147
148
149
150
151
152
153
154
155
119
120
121
122
123
124
125


126
127
128

129
130
131



132
133
134




135
136
137
138
139
140
141



142
143
144
145
146

147
148
149
150
151
152
153







-
-
+

+
-
+

+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+



-







		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURLHandler openItemAtURL: URL mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURLHandler openItemAtURL: URL mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[super dealloc];

Modified src/OFTarArchive.h from [a9bc537672] to [3b0b749343].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+







#import "OFKernelEventObserver.h"
#import "OFString.h"
#import "OFTarArchiveEntry.h"

OF_ASSUME_NONNULL_BEGIN

@class OFStream;
@class OFURL;

/**
 * @class OFTarArchive OFTarArchive.h ObjFW/OFTarArchive.h
 *
 * @brief A class for accessing and manipulating tar archives.
 */
OF_SUBCLASSING_RESTRICTED
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110

111
112
113
114
115
116
117
118
64
65
66
67
68
69
70

71
72
73

74
75
76
77
78
79

80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101

102
103
104
105
106
107

108

109
110
111
112
113
114
115







-



-
+





-
+
-

















-




-
+





-
+
-







 * @param mode The mode for the tar file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFTarArchive
 */
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFTarArchive object with the specified file.
 *
 * @param path The path to the tar archive
 * @param URL The URL to the tar archive
 * @param mode The mode for the tar file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFTarArchive
 */
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode;
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFTarArchive object with the
 *	  specified stream.
 *
 * @param stream A stream from which the tar archive will be read.
 *		 For append mode, this needs to be an OFSeekableStream.
 * @param mode The mode for the tar file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFTarArchive
 */
- (instancetype)initWithStream: (OFStream *)stream
			  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFTarArchive object with the
 *	  specified file.
 *
 * @param path The path to the tar archive
 * @param URL The URL to the tar archive
 * @param mode The mode for the tar file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFTarArchive
 */
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

/**
 * @brief Returns the next entry from the tar archive or `nil` if all entries
 *	  have been read.
 *
 * @note This is only available in read mode.
 *

Modified src/OFTarArchive.m from [5a61b65e4b] to [90c0fe7151].

19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
19
20
21
22
23
24
25


26

27
28
29
30
31
32
33







-
-
+
-








#import "OFTarArchive.h"
#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"
#import "OFDate.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#import "OFURLHandler.h"
#endif

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"
64
65
66
67
68
69
70
71
72

73
74

75
76
77
78
79
80
81
82
83
62
63
64
65
66
67
68


69
70

71
72

73
74
75
76
77
78
79







-
-
+

-
+

-







@synthesize encoding = _encoding;

+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode
{
	return [[[self alloc] initWithStream: stream mode: mode] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURL: URL mode: mode] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode
123
124
125
126
127
128
129
130
131

132

133

134

135
136
137



138
139
140
141







142
143
144


145
146
147
148
149
150
151
152
153
154
155
119
120
121
122
123
124
125


126
127
128

129
130
131



132
133
134




135
136
137
138
139
140
141



142
143
144
145
146

147
148
149
150
151
152
153







-
-
+

+
-
+

+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+



-







		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURLHandler openItemAtURL: URL mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURLHandler openItemAtURL: URL mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	[self close];

	[super dealloc];
}

Modified src/OFZIPArchive.h from [cd08e80056] to [b2dd9ca588].

70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117

118
119
120
121
122
123
124
125
70
71
72
73
74
75
76

77
78
79

80
81
82
83
84
85

86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107

108
109
110
111
112
113

114

115
116
117
118
119
120
121







-



-
+





-
+
-

















-




-
+





-
+
-







 * @param mode The mode for the ZIP file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFZIPArchive
 */
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFZIPArchive object with the specified file.
 *
 * @param path The path to the ZIP file
 * @param URL The URL to the ZIP file
 * @param mode The mode for the ZIP file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return A new, autoreleased OFZIPArchive
 */
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode;
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFZIPArchive object with the
 *	  specified stream.
 *
 * @param stream A stream from which the ZIP archive will be read.
 *		 For read and append mode, this needs to be an OFSeekableStream.
 * @param mode The mode for the ZIP file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFZIPArchive
 */
- (instancetype)initWithStream: (OFStream *)stream
			  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFZIPArchive object with the
 *	  specified file.
 *
 * @param path The path to the ZIP file
 * @param URL The URL to the ZIP file
 * @param mode The mode for the ZIP file. Valid modes are "r" for reading,
 *	       "w" for creating a new file and "a" for appending to an existing
 *	       archive.
 * @return An initialized OFZIPArchive
 */
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode;
#endif

/**
 * @brief Returns a stream for reading the specified file from the archive.
 *
 * @note This method is only available in read mode.
 *
 * @note The returned stream conforms to @ref OFReadyForReadingObserving if the

Modified src/OFZIPArchive.m from [2bbedc5f4d] to [eb2198be22].

16
17
18
19
20
21
22
23
24
25



26

27

28
29
30
31
32
33


34
35
36
37
38
39
40
16
17
18
19
20
21
22



23
24
25
26
27

28
29





30
31
32
33
34
35
36
37
38







-
-
-
+
+
+

+
-
+

-
-
-
-
-
+
+







#include "config.h"

#include <errno.h>

#import "OFZIPArchive.h"
#import "OFZIPArchiveEntry.h"
#import "OFZIPArchiveEntry+Private.h"
#import "OFCRC32.h"
#import "OFData.h"
#import "OFArray.h"
#import "OFArray.h"
#import "OFCRC32.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFInflate64Stream.h"
#import "OFStream.h"
#import "OFInflateStream.h"
#import "OFSeekableStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFInflateStream.h"
#import "OFInflate64Stream.h"
#import "OFStream.h"
#import "OFURLHandler.h"

#import "OFChecksumMismatchException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOpenItemFailedException.h"
160
161
162
163
164
165
166
167
168

169
170

171
172
173
174
175
176
177
178
179
158
159
160
161
162
163
164


165
166

167
168

169
170
171
172
173
174
175







-
-
+

-
+

-







@synthesize archiveComment = _archiveComment;

+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode
{
	return [[[self alloc] initWithStream: stream mode: mode] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURL: (OFURL *)URL mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURL: URL mode: mode] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode
219
220
221
222
223
224
225
226
227

228

229

230

231
232
233



234
235
236
237







238
239
240


241
242
243
244
245
246
247
248
249
250
251
215
216
217
218
219
220
221


222
223
224

225
226
227



228
229
230




231
232
233
234
235
236
237



238
239
240
241
242

243
244
245
246
247
248
249







-
-
+

+
-
+

+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+



-







		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURLHandler openItemAtURL: URL mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURLHandler openItemAtURL: URL mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[_stream release];