23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
@implementation OFTarURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
OFString *percentEncodedPath, *archiveURI, *path;
size_t pos;
OFTarArchive *archive;
OFTarArchiveEntry *entry;
if (![URI.scheme isEqual: @"of-tar"] || URI.host != nil ||
URI.port != nil || URI.user != nil || URI.password != nil ||
|
>
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
@implementation OFTarURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
void *pool = objc_autoreleasePoolPush();
OFString *percentEncodedPath, *archiveURI, *path;
size_t pos;
OFTarArchive *archive;
OFTarArchiveEntry *entry;
if (![URI.scheme isEqual: @"of-tar"] || URI.host != nil ||
URI.port != nil || URI.user != nil || URI.password != nil ||
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)]
.stringByRemovingPercentEncoding;
archive = [OFTarArchive
archiveWithURI: [OFURI URIWithString: archiveURI]
mode: @"r"];
while ((entry = [archive nextEntry]) != nil)
if ([entry.fileName isEqual: path])
return [archive streamForReadingCurrentEntry];
@throw [OFOpenItemFailedException exceptionWithURI: URI
mode: mode
errNo: ENOENT];
}
@end
|
|
|
>
|
>
>
>
>
>
>
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)]
.stringByRemovingPercentEncoding;
archive = [OFTarArchive
archiveWithURI: [OFURI URIWithString: archiveURI]
mode: @"r"];
while ((entry = [archive nextEntry]) != nil) {
if ([entry.fileName isEqual: path]) {
OFStream *stream =
[[archive streamForReadingCurrentEntry] retain];
objc_autoreleasePoolPop(pool);
return [stream autorelease];
}
}
@throw [OFOpenItemFailedException exceptionWithURI: URI
mode: mode
errNo: ENOENT];
}
@end
|