5 // Created by Alexander Strange on Thu Feb 27 2003.
6 // Copyright (c) 2003 __MyCompanyName__. All rights reserved.
9 #import "ITByteStream.h"
11 // TODO: Add NSCopying/NSCoding support. Blocking reads (how would this work? I could hack it with socketpair(), i guess)
13 @implementation ITByteStream
16 if (self == [super init])
18 data = [[NSMutableData alloc] init];
19 lock = [[NSLock alloc] init];
24 -(id) initWithStream:(ITByteStream*)stream
26 if (self == [super init])
28 data = [stream->data copy];
29 lock = [[NSLock alloc] init];
41 -(int) availableDataLength
46 -(NSData*) readDataOfLength:(int)length
49 NSRange range = {0, length};
51 ret = [data subdataWithRange:range];
52 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
53 [data replaceBytesInRange:range withBytes:nil length:0]; // this should delete off the end. should test.
55 range = {length, [data length]};
56 tmp = [data subdataWithRange:range];
57 [data setData:tmp]; // maybe i should add a lock to this? it would be bad if someone was writing when it was reading...
63 -(void) writeData:(NSData*)_data
66 [data appendData:_data];