X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/1ea39b0f18a93a1622b987e11b502b3b4ac2f821..c1dc61cc189c0eb83fe8027c70949b9c4dcdbd24:/ITByteStream.m?ds=sidebyside diff --git a/ITByteStream.m b/ITByteStream.m new file mode 100755 index 0000000..301d851 --- /dev/null +++ b/ITByteStream.m @@ -0,0 +1,62 @@ +// +// ITByteStream.h +// ITFoundation +// +// Created by Alexander Strange on Thu Feb 27 2003. +// Copyright (c) 2003 __MyCompanyName__. All rights reserved. +// + +#import "ITByteStream.h" + +// TODO: Add NSCopying/NSCoding support + +@implementation ITByteStream +-(id) init +{ + if (self == [super init]) + { + data = [[NSMutableData alloc] init]; + } + return self; +} + +-(id) initWithStream:(ITByteStream*)stream +{ + if (self == [super init]) + { + data = [stream->data copy]; + } + return 0; +} + +-(void) dealloc +{ + [data release]; + [super dealloc]; +} + +-(int) availableDataLength +{ + return [data length]; +} + +-(NSData*) readDataOfLength:(int)length +{ + NSData *ret, *tmp; + NSRange range = {0, length}; + ret = [data subdataWithRange:range]; +#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED + [data replaceBytesInRange:range withBytes:nil length:0]; // this should delete off the end. should test. +#else + range = {length, [data length]}; + tmp = [data subdataWithRange:range]; + [data setData:tmp]; // maybe i should add a lock to this? it would be bad if someone was writing when it was reading... +#endif + return ret; +} + +-(void) writeData:(NSData*)_data +{ + [data appendData:_data]; +} +@end