Merge pull request #164 from triplef/add-nsfilehandle-url-methods

Add NSFileHandle URL initializers.
This commit is contained in:
rfm 2020-11-18 09:21:13 +00:00 committed by GitHub
commit d27dcfbed6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 14 deletions

View file

@ -1,3 +1,12 @@
2020-11-17 Frederik Seiffert <frederik@algoriddim.com>
* Headers/Foundation/NSFileHandle.h,
* Source/NSFileHandle.h: Add NSFileHandle URL initializers:
-fileHandleForReadingFromURL:error:
-fileHandleForWritingToURL:error:
-fileHandleForUpdatingURL:error:
Also use "instancetype" for all initializers.
2020-10-11 Adam Fox <adam.fox@eggplantsoftware.com>
* Source/NSData.m: Implement rangeOfData:options:range.

View file

@ -38,18 +38,25 @@ extern "C" {
@class NSData;
@class NSString;
@class NSError;
@interface NSFileHandle : NSObject
// Allocating and Initializing a FileHandle Object
+ (id) fileHandleForReadingAtPath: (NSString*)path;
+ (id) fileHandleForWritingAtPath: (NSString*)path;
+ (id) fileHandleForUpdatingAtPath: (NSString*)path;
+ (id) fileHandleWithStandardError;
+ (id) fileHandleWithStandardInput;
+ (id) fileHandleWithStandardOutput;
+ (id) fileHandleWithNullDevice;
+ (instancetype) fileHandleForReadingAtPath: (NSString*)path;
+ (instancetype) fileHandleForWritingAtPath: (NSString*)path;
+ (instancetype) fileHandleForUpdatingAtPath: (NSString*)path;
+ (instancetype) fileHandleWithStandardError;
+ (instancetype) fileHandleWithStandardInput;
+ (instancetype) fileHandleWithStandardOutput;
+ (instancetype) fileHandleWithNullDevice;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
+ (instancetype) fileHandleForReadingFromURL: (NSURL*)url error:(NSError**)error;
+ (instancetype) fileHandleForWritingToURL: (NSURL*)url error:(NSError**)error;
+ (instancetype) fileHandleForUpdatingURL: (NSURL*)url error:(NSError**)error;
#endif
- (id) initWithFileDescriptor: (int)desc;
- (id) initWithFileDescriptor: (int)desc closeOnDealloc: (BOOL)flag;

View file

@ -200,15 +200,9 @@ NSExpression:
- rightExpression
- expressionBlock
-------------------------------------------------------------
NSFileHandler:
NSFileHandle:
<NSArray.h>
@class NSError
+ fileHandleForReadingFromURL:error:
+ fileHandleForWritingToURL:error:
+ fileHandleForUpdatingURL:error:
@property (copy) void (^readabilityHandler)(NSFileHandle *)
@property (copy) void (^writeabilityHandler)(NSFileHandle *)
-------------------------------------------------------------

View file

@ -32,6 +32,7 @@
#import "Foundation/NSHost.h"
#import "Foundation/NSFileHandle.h"
#import "Foundation/NSPathUtilities.h"
#import "Foundation/NSURL.h"
#import "GNUstepBase/GSTLS.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
#import "GSPrivate.h"
@ -198,6 +199,36 @@ static Class NSFileHandle_ssl_class = nil;
return AUTORELEASE([o initWithNullDevice]);
}
+ (id) fileHandleForReadingFromURL: (NSURL*)url error:(NSError**)error
{
id o = [self fileHandleForReadingAtPath: [url path]];
if (!o && error)
{
*error = [NSError _last];
}
return o;
}
+ (id) fileHandleForWritingToURL: (NSURL*)url error:(NSError**)error
{
id o = [self fileHandleForWritingAtPath: [url path]];
if (!o && error)
{
*error = [NSError _last];
}
return o;
}
+ (id) fileHandleForUpdatingURL: (NSURL*)url error:(NSError**)error
{
id o = [self fileHandleForUpdatingAtPath: [url path]];
if (!o && error)
{
*error = [NSError _last];
}
return o;
}
/**
* Initialize with desc, which can point to either a regular file or
* socket connection.