Skip to content

Commit 9189207

Browse files
authored
Merge pull request #510 from gnustep/file-handle-refactor
feat(NSFileHandle): Add new APIs with error handling, and refactor GSFileHandle
2 parents 09c7b9c + c41b256 commit 9189207

5 files changed

Lines changed: 279 additions & 62 deletions

File tree

Headers/Foundation/NSFileHandle.h

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,29 @@ GS_EXPORT_CLASS
7373

7474
- (NSData*) availableData;
7575
- (NSData*) readDataToEndOfFile;
76-
- (NSData*) readDataOfLength: (unsigned int)len;
76+
- (NSData*) readDataOfLength: (NSUInteger)len;
7777
- (void) writeData: (NSData*)item;
7878

79+
#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST)
80+
/**
81+
* Writes the specified data synchronously to the file handle.
82+
*/
83+
- (BOOL) writeData: (NSData *) data
84+
error: (NSError **) error;
85+
86+
/**
87+
* Reads the data synchronously up to the specified number of bytes.
88+
*/
89+
- (NSData *) readDataUpToLength: (NSUInteger) length
90+
error: (NSError **) error;
91+
92+
/**
93+
* Reads the data synchronously up to the end of file or maximum number of
94+
* bytes.
95+
*/
96+
- (NSData *) readDataToEndOfFileAndReturnError: (NSError **) error;
97+
#endif
98+
7999
// Asynchronous I/O operations
80100

81101
- (void) acceptConnectionInBackgroundAndNotify;
@@ -93,23 +113,36 @@ GS_EXPORT_CLASS
93113
- (unsigned long long) seekToEndOfFile;
94114
- (void) seekToFileOffset: (unsigned long long)pos;
95115

96-
// Operations on file
116+
#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST)
117+
/**
118+
* Get the current position of the file pointer within the file.
119+
*/
120+
- (BOOL) getOffset: (unsigned long long *) offsetInFile
121+
error: (NSError **) error;
97122

98-
- (void) closeFile;
99-
- (void) synchronizeFile;
100-
- (void) truncateFileAtOffset: (unsigned long long)pos;
123+
/**
124+
* Sets the file pointer at the end of the file and returns the new file offset.
125+
*/
126+
- (BOOL) seekToEndReturningOffset: (unsigned long long *) offsetInFile
127+
error: (NSError **) error;
128+
129+
/**
130+
* Sets the file pointer to the specified offset within the file.
131+
*/
132+
- (BOOL) seekToOffset: (unsigned long long) offset
133+
error: (NSError **) error;
101134

102-
#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST)
103-
- (BOOL) getOffset: (out unsigned long long *)offsetInFile
104-
error: (out NSError **)error;
105-
- (BOOL) seekToEndReturningOffset: (out unsigned long long *)offsetInFile
106-
error: (out NSError **)error;
107-
- (BOOL) seekToOffset: (unsigned long long)offset
108-
error: (out NSError **)error;
109135
- (BOOL) truncateAtOffset: (unsigned long long)offset
110136
error: (out NSError **)error;
137+
111138
#endif
112139

140+
// Operations on file
141+
142+
- (void) closeFile;
143+
- (void) synchronizeFile;
144+
- (void) truncateFileAtOffset: (unsigned long long)pos;
145+
113146
@end
114147

115148
// Notification names.

0 commit comments

Comments
 (0)