ASIInputStream.m
1.49 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
//
// ASIInputStream.m
// Mac
//
// Created by Ben Copsey on 10/08/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import "ASIInputStream.h"
#import "ASIHTTPRequest.h"
@implementation ASIInputStream
+ (id)inputStreamWithFileAtPath:(NSString *)path
{
ASIInputStream *stream = [[[self alloc] init] autorelease];
[stream setStream:[NSInputStream inputStreamWithFileAtPath:path]];
return stream;
}
+ (id)inputStreamWithData:(NSData *)data
{
ASIInputStream *stream = [[[self alloc] init] autorelease];
[stream setStream:[NSInputStream inputStreamWithData:data]];
return stream;
}
- (void)dealloc
{
[stream release];
[super dealloc];
}
- (BOOL)hasBytesAvailable
{
if ([ASIHTTPRequest maxUploadReadLength] == 0) {
NSLog(@"no");
return NO;
}
NSLog(@"yes");
return [[self stream] hasBytesAvailable];
}
- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len
{
unsigned long toRead = [ASIHTTPRequest maxUploadReadLength];
//NSLog(@"may read %lu",toRead);
if (toRead > len) {
toRead = len;
} else if (toRead == 0) {
toRead = 1;
}
//toRead = len;
[ASIHTTPRequest incrementBandwidthUsedInLastSecond:toRead];
//NSLog(@"will read %lu",toRead);
return [[self stream] read:buffer maxLength:toRead];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
return [[self stream] methodSignatureForSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation invokeWithTarget:[self stream]];
}
@synthesize stream;
@end