ObjFW  Check-in [9c4d3e34cd]

Overview
Comment:Add +[OFDataArray dataArrayWithContentsOfURL:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9c4d3e34cdb6a18cfeb70d099e324998729005f82056d14add9645343f04459b
User & Date: js on 2011-04-25 00:18:06
Other Links: manifest | tags
Context
2011-04-25
11:09
Fix a forgotten variable rename in objc_sync.m. check-in: b466a2bb49 user: js tags: trunk
00:18
Add +[OFDataArray dataArrayWithContentsOfURL:]. check-in: 9c4d3e34cd user: js tags: trunk
2011-04-24
21:50
Add -[finalize] to all classes which would require it once we have GC. check-in: 07b3d0e8de user: js tags: trunk
Changes

Modified src/OFDataArray.h from [52c9a087ea] to [0e4d25200c].

13
14
15
16
17
18
19

20
21
22
23
24
25
26
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

@class OFString;


/**
 * \brief A class for storing arbitrary data in an array.
 *
 * If you plan to store large hunks of data, you should consider using
 * OFBigDataArray, which allocates the memory in pages rather than in bytes.
 */







>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

@class OFString;
@class OFURL;

/**
 * \brief A class for storing arbitrary data in an array.
 *
 * If you plan to store large hunks of data, you should consider using
 * OFBigDataArray, which allocates the memory in pages rather than in bytes.
 */
49
50
51
52
53
54
55









56
57
58
59
60
61
62
 * specified file.
 *
 * \param path The path of the file
 * \return A new autoreleased OFDataArray
 */
+ dataArrayWithContentsOfFile: (OFString*)path;










/**
 * Creates a new OFDataArray with an item size of 1, containing the data of the
 * Base64-encoded string.
 *
 * \param string The string with the Base64-encoded data
 * \return A new autoreleased OFDataArray
 */







>
>
>
>
>
>
>
>
>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 * specified file.
 *
 * \param path The path of the file
 * \return A new autoreleased OFDataArray
 */
+ dataArrayWithContentsOfFile: (OFString*)path;

/**
 * Creates a new OFDataArray with an item size of 1, containing the data of the
 * specified URL.
 *
 * \param URL The URL to the contents for the OFDataArray
 * \return A new autoreleased OFDataArray
 */
+ dataArrayWithContentsOfURL: (OFURL*)URL;

/**
 * Creates a new OFDataArray with an item size of 1, containing the data of the
 * Base64-encoded string.
 *
 * \param string The string with the Base64-encoded data
 * \return A new autoreleased OFDataArray
 */
76
77
78
79
80
81
82









83
84
85
86
87
88
89
 * containing the data of the specified file.
 *
 * \param path The path of the file
 * \return An initialized OFDataArray
 */
- initWithContentsOfFile: (OFString*)path;










/**
 * Initializes an already allocated OFDataArray with an item size of 1,
 * containing the data of the Base64-encoded string.
 *
 * \param string The string with the Base64-encoded data
 * \return A initialized OFDataArray
 */







>
>
>
>
>
>
>
>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 * containing the data of the specified file.
 *
 * \param path The path of the file
 * \return An initialized OFDataArray
 */
- initWithContentsOfFile: (OFString*)path;

/**
 * Initializes an already allocated OFDataArray with an item size of 1,
 * containing the data of the specified URL.
 *
 * \param URL The URL to the contents for the OFDataArray
 * \return A new autoreleased OFDataArray
 */
- initWithContentsOfURL: (OFURL*)URL;

/**
 * Initializes an already allocated OFDataArray with an item size of 1,
 * containing the data of the Base64-encoded string.
 *
 * \param string The string with the Base64-encoded data
 * \return A initialized OFDataArray
 */

Modified src/OFDataArray.m from [c17a542e4e] to [b6f607f8d4].

19
20
21
22
23
24
25



26

27
28
29
30
31
32
33
#include <stdio.h>
#include <string.h>
#include <limits.h>

#import "OFDataArray.h"
#import "OFString.h"
#import "OFFile.h"





#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "base64.h"







>
>
>

>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <string.h>
#include <limits.h>

#import "OFDataArray.h"
#import "OFString.h"
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPRequest.h"
#import "OFAutoreleasePool.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "base64.h"
45
46
47
48
49
50
51





52
53
54
55
56
57
58
	return [[[self alloc] initWithItemSize: itemSize] autorelease];
}

+ dataArrayWithContentsOfFile: (OFString*)path
{
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}






+ dataArrayWithBase64EncodedString: (OFString*)string
{
	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- init







>
>
>
>
>







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	return [[[self alloc] initWithItemSize: itemSize] autorelease];
}

+ dataArrayWithContentsOfFile: (OFString*)path
{
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}

+ dataArrayWithContentsOfURL: (OFURL*)URL
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}

+ dataArrayWithBase64EncodedString: (OFString*)string
{
	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- init
112
113
114
115
116
117
118
































119
120
121
122
123
124
125
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

































- initWithBase64EncodedString: (OFString*)string
{
	self = [super init];

	itemSize = 1;
	data = NULL;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
154
155
156
157
158
159
160
161
162
163
164
165
166
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithContentsOfURL: (OFURL*)URL
{
	OFAutoreleasePool *pool;
	OFHTTPRequest *request;
	OFHTTPRequestResult *result;
	Class c;

	c = isa;
	[self release];

	pool = [[OFAutoreleasePool alloc] init];

	if ([[URL scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [URL path]];
		[pool release];
		return self;
	}

	request = [OFHTTPRequest requestWithURL: URL];
	result = [request perform];

	if ([result statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    newWithClass: [request class]
		     HTTPRequest: request
		      statusCode: [result statusCode]];

	self = [[result data] retain];
	[pool release];
	return self;
}

- initWithBase64EncodedString: (OFString*)string
{
	self = [super init];

	itemSize = 1;
	data = NULL;

Modified src/OFString.m from [878e982a3d] to [18e15c80ab].

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
	OFAutoreleasePool *pool;
	OFHTTPRequest *request;
	OFHTTPRequestResult *result;
	Class c;

	c = isa;
	[self release];
	self = nil;

	pool = [[OFAutoreleasePool alloc] init];

	if ([[URL scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [URL path]
						encoding: encoding];
		[pool release];







<







705
706
707
708
709
710
711

712
713
714
715
716
717
718
	OFAutoreleasePool *pool;
	OFHTTPRequest *request;
	OFHTTPRequestResult *result;
	Class c;

	c = isa;
	[self release];


	pool = [[OFAutoreleasePool alloc] init];

	if ([[URL scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [URL path]
						encoding: encoding];
		[pool release];