Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSFileHandleMBS class.

NSFileHandleMBS.fileHandleForReadingAtFile(path as folderitem) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading the file, device, or named socket at the specified path.
Example
// file must exist for this sample:

dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt")
dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleForReadingAtFile(f)

if n<>Nil then
MsgBox n.readDataToEndOfFile
end if

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds only to NSFileHandle read... messages.

Some examples using this method:

NSFileHandleMBS.fileHandleForReadingAtPath(path as string) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading the file, device, or named socket at the specified path.

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds only to NSFileHandle read... messages.

NSFileHandleMBS.fileHandleForReadingFromFile(URL as folderitem, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading the file, device, or named socket at the specified URL.
Example
// file must exist for this sample:

dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt")
dim e as NSErrorMBS
dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleForReadingFromFile(f,e)

if e<>Nil then
MsgBox e.localizedDescription
end if

if n<>Nil then
MsgBox n.readDataOfLength(5)
MsgBox str(n.offsetInFile) // shows 5
end if

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns the initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds only to NSFileHandleread... messages.

NSFileHandleMBS.fileHandleForReadingFromURL(URL as string, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading the file, device, or named socket at the specified URL.

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns the initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds only to NSFileHandleread... messages.

NSFileHandleMBS.fileHandleForUpdatingAtFile(path as folderitem) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified path.

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds to both NSFileHandle read... messages and writeData.

NSFileHandleMBS.fileHandleForUpdatingAtPath(path as string) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified path.

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds to both NSFileHandle read... messages and writeData.

NSFileHandleMBS.fileHandleForUpdatingFile(URL as folderitem, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified URL.

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

The initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds to both NSFileHandleread... messages and writeData.

NSFileHandleMBS.fileHandleForUpdatingURL(URL as string, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified URL.

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

The initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds to both NSFileHandleread... messages and writeData.

NSFileHandleMBS.fileHandleForWritingAtFile(path as folderitem) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for writing to the file, device, or named socket at the specified path.
Example
// file must exist for this sample:

dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt")
dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleForWritingAtFile(f)

if n<>Nil then
n.writeData "Hello World"
n.closeFile
end if

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds only to writeData.

NSFileHandleMBS.fileHandleForWritingAtPath(path as string) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for writing to the file, device, or named socket at the specified path.

path: The path to the file, device, or named socket to access.

Returns the initialized file handle, or nil if no file exists at path.

The file pointer is set to the beginning of the file. The returned object responds only to writeData.

NSFileHandleMBS.fileHandleForWritingToFile(URL as folderitem, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for writing to the file, device, or named socket at the specified URL.
Example
// file must exist for this sample:

dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt")
dim e as NSErrorMBS
dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleForWritingToFile(f, e)

if e<>Nil then
MsgBox e.localizedDescription
else
n.writeData "Hello World"
n.closeFile
end if

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns the initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds only to writeData.

NSFileHandleMBS.fileHandleForWritingToURL(URL as string, byref error as NSErrorMBS) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized for writing to the file, device, or named socket at the specified URL.

url: The URL of the file, device, or named socket to access.
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns the initialized file handle, or nil if no file exists at url.

The file pointer is set to the beginning of the file. The returned object responds only to writeData.

NSFileHandleMBS.fileHandleWithFileDescriptor(fd as Integer) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized with a file descriptor.

You can create a file handle for a socket by using the result of a socket call as fileDescriptor.
The object creating a file handle using this method owns fileDescriptor and is responsible for its disposition.

See also:

NSFileHandleMBS.fileHandleWithFileDescriptor(fd as Integer, closeOnDealloc as boolean) as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle initialized with a file descriptor.

You can create a file handle for a socket by using the result of a socket call as fileDescriptor.
The object creating a file handle using this method owns fileDescriptor and is responsible for its disposition.

closeOnDealloc: True if the file descriptor should be closed when the receiver is deallocated, otherwise false.

See also:

NSFileHandleMBS.fileHandleWithNullDevice as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a file handle associated with a null device.

You can use null-device file handles as "placeholders" for standard-device file handles or in collection objects to avoid exceptions and other errors resulting from messages being sent to invalid file handles. Read messages sent to a null-device file handle return an end-of-file indicator (an empty NSData object) rather than raise an exception. Write messages are no-ops, whereas fileDescriptor returns an illegal value. Other methods are no-ops or return "sensible" values.

NSFileHandleMBS.fileHandleWithStandardError as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the file handle associated with the standard error file.
Example
// for GUI apps this ends on the console: (see console.app)

dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleWithStandardError

n.writeData "Hello World"

Conventionally this is a terminal device to which error messages are sent. There is one standard error file handle per process; it is a shared instance.

NSFileHandleMBS.fileHandleWithStandardInput as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the file handle associated with the standard input file.

Conventionally this is a terminal device on which the user enters a stream of data. There is one standard input file handle per process; it is a shared instance.

NSFileHandleMBS.fileHandleWithStandardOutput as NSFileHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the file handle associated with the standard output file.
Example
// for GUI apps this ends on the console: (see console.app)

dim n as NSFileHandleMBS = NSFileHandleMBS.fileHandleWithStandardOutput

n.writeData "Hello World"

Conventionally this is a terminal device that receives a stream of data from a program. There is one standard output file handle per process; it is a shared instance.

NSFileHandleMBS.NSFileHandleConnectionAcceptedNotification as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
This notification is posted when an NSFileHandle object establishes a socket connection between two processes, creates an NSFileHandle object for one end of the connection, and makes this object available to observers by putting it in the userInfo dictionary.

To cause the posting of this notification, you must send either acceptConnectionInBackgroundAndNotify to an NSFileHandle object representing a server stream-type socket.
The notification object is the NSFileHandle object that sent the notification. The userInfo dictionary contains the following information:

NSFileHandleNotificationFileHandleItemThe NSFileHandle object representing the "near" end of a socket connection
NSFileHandleErrorAn integer representing the UNIX-type error which occurred

NSFileHandleMBS.NSFileHandleDataAvailableNotification as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
This notification is posted when the background thread determines that data is currently available for reading in a file or at a communications channel.

The observers can then issue the appropriate messages to begin reading the data. To cause the posting of this notification, you must send either waitForDataInBackgroundAndNotify or waitForDataInBackgroundAndNotifyForModes: to an appropriate NSFileHandle object.
The notification object is the NSFileHandle object that sent the notification. This notification does not contain a userInfo dictionary.

NSFileHandleMBS.NSFileHandleNotificationDataItem as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
A key in the userinfo dictionary in a NSFileHandleReadCompletionNotification and NSFileHandleReadToEndOfFileCompletionNotification.

The corresponding value is an memoryblock containing the available data read from a socket connection.

Some examples using this method:

NSFileHandleMBS.NSFileHandleNotificationFileHandleItem as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
A key in the userinfo dictionary in a NSFileHandleConnectionAcceptedNotification notification.

The corresponding value is the NSFileHandle object handle representing the "near" end of a socket connection.

NSFileHandleMBS.NSFileHandleNotificationMonitorModes as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Currently unused.

NSFileHandleMBS.NSFileHandleOperationException as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Constant that defines the name of a file operation exception.

Raised by NSFileHandle if attempts to determine file-handle type fail or if attempts to read from a file or channel fail.

NSFileHandleMBS.NSFileHandleReadCompletionNotification as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the notification strings for the file handle class.

This notification is posted when the background thread reads the data currently available in a file or at a communications channel. It makes the data available to observers by putting it in the userInfo dictionary. To cause the posting of this notification, you must send either readInBackgroundAndNotify to an appropriate NSFileHandle object.
The notification object is the NSFileHandle object that sent the notification. The userInfo dictionary contains the following information:

NSFileHandleNotificationDataItemAn string containing the available data read from a socket connection
NSFileHandleErrorAn integer representing the UNIX-type error which occurred

Some examples using this method:

NSFileHandleMBS.NSFileHandleReadToEndOfFileCompletionNotification as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Tasks MBS MacCocoa Plugin 9.7 ✅ Yes ❌ No ❌ No ✅ Yes All
This notification is posted when the background thread reads all data in the file or, if a communications channel, until the other process signals the end of data.

It makes the data available to observers by putting it in the userInfo dictionary. To cause the posting of this notification, you must send either readToEndOfFileInBackgroundAndNotify to an appropriate NSFileHandle object.
The notification object is the NSFileHandle object that sent the notification. The userInfo dictionary contains the following information:

NSFileHandleNotificationDataItem: A string containing the available data read from a socket connection
NSFileHandleErrorAn integer representing the UNIX-type error which occurred

Some examples using this method:

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...