ObjFW  Diff

Differences From Artifact [4c3a4649ab]:

To Artifact [8e5558d27e]:


20
21
22
23
24
25
26

27
28
29
30

31
32

33
34
35
36

37
38

39
40
41
42

43
44
45

46









47
48
49
50
51
52

53
54
55
56
57

58
59
60
61
62
63
64
#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"
#import "OFStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif


#import "OFInvalidFormatException.h"

@implementation OFTarArchive: OFObject
+ (instancetype)archiveWithStream: (OFStream *)stream

{
	return [[[self alloc] initWithStream: stream] autorelease];

}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path

{
	return [[[self alloc] initWithPath: path] autorelease];

}
#endif

- initWithStream: (OFStream *)stream

{
	self = [super init];


	_stream = [stream retain];










	return self;
}

#ifdef OF_HAVE_FILES
- initWithPath: (OFString *)path

{
	OFFile *file = [[OFFile alloc] initWithPath: path
					       mode: @"r"];
	@try {
		self = [self initWithStream: file];

	} @finally {
		[file release];
	}

	return self;
}
#endif







>




>

|
>




>

|
>




>



>
|
>
>
>
>
>
>
>
>
>






>


|

|
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"
#import "OFStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"

@implementation OFTarArchive: OFObject
+ (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
{
	return [[[self alloc] initWithPath: path
				      mode: mode] autorelease];
}
#endif

- initWithStream: (OFStream *)stream
	    mode: (OFString *)mode
{
	self = [super init];

	@try {
		_stream = [stream retain];

		if ([mode isEqual: @"r"])
			_mode = OF_TAR_ARCHIVE_MODE_READ;
		else
			@throw [OFInvalidArgumentException exception];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- initWithPath: (OFString *)path
	  mode: (OFString *)mode
{
	OFFile *file = [[OFFile alloc] initWithPath: path
					       mode: mode];
	@try {
		self = [self initWithStream: file
				       mode: mode];
	} @finally {
		[file release];
	}

	return self;
}
#endif
75
76
77
78
79
80
81



82
83
84
85
86
87
88
{
	union {
		char c[512];
		uint32_t u32[512 / sizeof(uint32_t)];
	} buffer;
	bool empty = true;




	[_lastReturnedEntry of_skip];
	[_lastReturnedEntry close];
	[_lastReturnedEntry release];
	_lastReturnedEntry = nil;

	if ([_stream isAtEndOfStream])
		return nil;







>
>
>







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
	union {
		char c[512];
		uint32_t u32[512 / sizeof(uint32_t)];
	} buffer;
	bool empty = true;

	if (_mode != OF_TAR_ARCHIVE_MODE_READ)
		@throw [OFInvalidArgumentException exception];

	[_lastReturnedEntry of_skip];
	[_lastReturnedEntry close];
	[_lastReturnedEntry release];
	_lastReturnedEntry = nil;

	if ([_stream isAtEndOfStream])
		return nil;