-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCoreAssetURLConnection.m
More file actions
83 lines (66 loc) · 2.03 KB
/
CoreAssetURLConnection.m
File metadata and controls
83 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
83
//
// CoreAssetURLConnection.m
// CoreAssetManager
//
// Created by Bálint Róbert on 04/05/15.
// Copyright (c) 2015 IncepTech Ltd All rights reserved.
//
#import "CoreAssetURLConnection.h"
//#import "CoreAssetItemPDF.h"
#import "CoreAssetItemImage.h"
@implementation CoreAssetURLConnection
- (instancetype)init {
self = [super init];
if (self) {
[self initialize];
}
return self;
}
- (void)initialize {
_assetItem = nil;
_connectionData = nil;
_connectionDataExpectedLength = 0;
}
- (void)appendData:(NSData *)data {
if (!_connectionData) {
NSUInteger sizeHint = 64 * 1024;
if (_connectionDataExpectedLength) {
sizeHint = (NSUInteger)_connectionDataExpectedLength;
}
else {
/*if ([assetItem isKindOfClass:[CoreAssetItemPDF class]]) {
sizeHint = 1 * 1024 * 1024;
}
else */if ([_assetItem isKindOfClass:[CoreAssetItemImage class]]) {
sizeHint = 128 * 1024;
}
}
_connectionData = [[NSMutableData alloc] initWithCapacity:sizeHint];
}
[_connectionData appendData:data];
}
- (void)appendBytes:(const void *)bytes length:(NSUInteger)length {
if (!_connectionData) {
NSUInteger sizeHint = 64 * 1024;
if (_connectionDataExpectedLength) {
sizeHint = (NSUInteger)_connectionDataExpectedLength;
}
else {
/*if ([assetItem isKindOfClass:[CoreAssetItemPDF class]]) {
sizeHint = 1 * 1024 * 1024;
}
else */if ([_assetItem isKindOfClass:[CoreAssetItemImage class]]) {
sizeHint = 128 * 1024;
}
}
_connectionData = [[NSMutableData alloc] initWithCapacity:sizeHint];
}
[_connectionData appendBytes:bytes length:length];
}
- (BOOL)validLength {
if (!_connectionDataExpectedLength) {
return YES;
}
return _connectionData.length == _connectionDataExpectedLength;
}
@end