Author: rfm
Date: Mon Mar 27 11:44:13 2017
New Revision: 40420

URL: http://svn.gna.org/viewcvs/gnustep?rev=40420&view=rev
Log:
implement methods to create a stream to read from a URL

Modified:
    libs/base/trunk/Headers/Foundation/NSStream.h
    libs/base/trunk/Source/unix/NSStream.m
    libs/base/trunk/Source/win32/NSStream.m

Modified: libs/base/trunk/Headers/Foundation/NSStream.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/Foundation/NSStream.h?rev=40420&r1=40419&r2=40420&view=diff
==============================================================================
--- libs/base/trunk/Headers/Foundation/NSStream.h       (original)
+++ libs/base/trunk/Headers/Foundation/NSStream.h       Mon Mar 27 11:44:13 2017
@@ -161,6 +161,12 @@
 + (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.
  */
@@ -183,6 +189,12 @@
  * specified path.
  */
 - (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.

Modified: libs/base/trunk/Source/unix/NSStream.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/unix/NSStream.m?rev=40420&r1=40419&r2=40420&view=diff
==============================================================================
--- libs/base/trunk/Source/unix/NSStream.m      (original)
+++ libs/base/trunk/Source/unix/NSStream.m      Mon Mar 27 11:44:13 2017
@@ -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];
@@ -529,6 +539,17 @@
 {
   DESTROY(self);
   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

Modified: libs/base/trunk/Source/win32/NSStream.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/win32/NSStream.m?rev=40420&r1=40419&r2=40420&view=diff
==============================================================================
--- libs/base/trunk/Source/win32/NSStream.m     (original)
+++ libs/base/trunk/Source/win32/NSStream.m     Mon Mar 27 11:44:13 2017
@@ -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 @@
   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];
@@ -1224,6 +1234,17 @@
 {
   DESTROY(self);
   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


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to