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? NSConditionLock?)
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
50 -(NSData*) readDataOfLength:(int)length
53 NSRange range = {0, length};
55 ret = [data subdataWithRange:range];
56 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
57 [data replaceBytesInRange:range withBytes:nil length:0];
59 range = {length, [data length]};
60 tmp = [data subdataWithRange:range];
67 -(void) writeData:(NSData*)_data
70 [data appendData:_data];