diff --git a/Headers/Foundation/NSStream.h b/Headers/Foundation/NSStream.h index db35716c8..9f8a3b80d 100644 --- a/Headers/Foundation/NSStream.h +++ b/Headers/Foundation/NSStream.h @@ -160,6 +160,12 @@ typedef NSUInteger NSStreamEvent; */ + (id) inputStreamWithFileAtPath: (NSString *)path; +/** + * Creates and returns an initialized NSInputStream object that reads data from + * the specified URL. + */ ++ (id) inputStreamWithURL: (NSURL *)url; + /** * Returns a pointer to the read buffer in buffer and, by reference, the number * of bytes available in len. @@ -184,6 +190,12 @@ typedef NSUInteger NSStreamEvent; */ - (id) initWithFileAtPath: (NSString *)path; +/** + * Returns an initialized NSInputStream object for reading from the + * specified URL. + */ +- (id) initWithURL: (NSURL *)url; + /** * Reads up to len bytes into buffer, returning the actual number of bytes read. */ diff --git a/Source/unix/NSStream.m b/Source/unix/NSStream.m index 4ef99747d..b0fd9421d 100644 --- a/Source/unix/NSStream.m +++ b/Source/unix/NSStream.m @@ -43,6 +43,7 @@ #import "Foundation/NSValue.h" #import "Foundation/NSHost.h" #import "Foundation/NSByteOrder.h" +#import "Foundation/NSURL.h" #import "GNUstepBase/NSObject+GNUstepBase.h" #import "../GSPrivate.h" @@ -507,6 +508,15 @@ return AUTORELEASE([[GSFileInputStream alloc] initWithFileAtPath: path]); } ++ (id) inputStreamWithURL: (NSURL *)url +{ + if ([url isFileURL]) + { + return [self inputStreamWithFileAtPath: [url path]]; + } + return [self inputStreamWithData: [url resourceDataUsingCache: YES]]; +} + - (BOOL) getBuffer: (uint8_t **)buffer length: (NSUInteger *)len { [self subclassResponsibility: _cmd]; @@ -531,6 +541,17 @@ return [[GSFileInputStream alloc] initWithFileAtPath: path]; } +- (id) initWithURL: (NSURL *)url +{ + DESTROY(self); + if ([url isFileURL]) + { + return [[GSFileInputStream alloc] initWithFileAtPath: [url path]]; + } + return [[GSDataInputStream alloc] + initWithData: [url resourceDataUsingCache: YES]]; +} + - (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len { [self subclassResponsibility: _cmd]; diff --git a/Source/win32/NSStream.m b/Source/win32/NSStream.m index ee82db361..b4388fc5a 100644 --- a/Source/win32/NSStream.m +++ b/Source/win32/NSStream.m @@ -34,6 +34,7 @@ #import "Foundation/NSHost.h" #import "Foundation/NSProcessInfo.h" #import "Foundation/NSByteOrder.h" +#import "Foundation/NSURL.h" #import "GNUstepBase/NSObject+GNUstepBase.h" #import "../GSPrivate.h" @@ -1202,6 +1203,15 @@ done: return AUTORELEASE([[GSFileInputStream alloc] initWithFileAtPath: path]); } ++ (id) inputStreamWithURL: (NSURL *)url +{ + if ([url isFileURL]) + { + return [self inputStreamWithFileAtPath: [url path]]; + } + return [self inputStreamWithData: [url resourceDataUsingCache: YES]]; +} + - (BOOL) getBuffer: (uint8_t **)buffer length: (NSUInteger *)len { [self subclassResponsibility: _cmd]; @@ -1226,6 +1236,17 @@ done: return [[GSFileInputStream alloc] initWithFileAtPath: path]; } +- (id) initWithURL: (NSURL *)url +{ + DESTROY(self); + if ([url isFileURL]) + { + return [[GSFileInputStream alloc] initWithFileAtPath: [url path]]; + } + return [[GSDataInputStream alloc] + initWithData: [url resourceDataUsingCache: YES]]; +} + - (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len { [self subclassResponsibility: _cmd];