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
|
#import "OFZIPArchiveEntry+Private.h"
#import "OFDataArray.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFInflateStream.h"
#import "OFInflate64Stream.h"
#import "OFChecksumFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFUnsupportedVersionException.h"
#define CRC32_MAGIC 0xEDB88320
/*
* FIXME: Current limitations:
* - Split archives are not supported.
* - Write support is missing.
* - The ZIP has to be a file on the local file system.
* - Encrypted files cannot be read.
*/
|
>
>
<
<
|
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
|
#import "OFZIPArchiveEntry+Private.h"
#import "OFDataArray.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFInflateStream.h"
#import "OFInflate64Stream.h"
#import "crc32.h"
#import "OFChecksumFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFUnsupportedVersionException.h"
/*
* FIXME: Current limitations:
* - Split archives are not supported.
* - Write support is missing.
* - The ZIP has to be a file on the local file system.
* - Encrypted files cannot be read.
*/
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
*data += 8;
*size -= 8;
return field;
}
static uint32_t
calculateCRC32(uint32_t crc, uint8_t *bytes, size_t length)
{
for (size_t i = 0; i < length; i++) {
crc ^= bytes[i];
for (uint8_t j = 0; j < 8; j++)
crc = (crc >> 1) ^ (CRC32_MAGIC & (~(crc & 1) + 1));
}
return crc;
}
static void
seekOrThrowInvalidFormat(OFSeekableStream *stream,
of_offset_t offset, int whence)
{
@try {
[stream seekToOffset: offset
whence: whence];
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
*data += 8;
*size -= 8;
return field;
}
static void
seekOrThrowInvalidFormat(OFSeekableStream *stream,
of_offset_t offset, int whence)
{
@try {
[stream seekToOffset: offset
whence: whence];
|
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
min = (length < _size ? length : (size_t)_size);
ret = [_decompressedStream readIntoBuffer: buffer
length: min];
_size -= ret;
}
_CRC32 = calculateCRC32(_CRC32, buffer, ret);
return ret;
}
- (void)close
{
_closed = true;
}
@end
|
|
|
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
min = (length < _size ? length : (size_t)_size);
ret = [_decompressedStream readIntoBuffer: buffer
length: min];
_size -= ret;
}
_CRC32 = of_crc32(_CRC32, buffer, ret);
return ret;
}
- (void)close
{
_closed = true;
}
@end
|