# NSStream documentation

derekzhou@gmail.com
Generated at 2025-09-10 09:16:48 +0000
2006 Free Software Foundation, Inc.
Software documentation for the NSInputStream class
Foundation/NSStream.h
NSInputStream is a subclass of NSStream that provides read-only stream functionality.
inputStreamWithData:
data
Creates and returns an initialized NSInputStream object for reading from data.
inputStreamWithFileAtPath:
path
Creates and returns an initialized NSInputStream object that reads data from the file at the specified path.
inputStreamWithURL:
url
Creates and returns an initialized NSInputStream object that reads data from the specified URL.
getBuffer:
buffer
length:
len
Returns a pointer to the read buffer in buffer and, by reference, the number of bytes available in len.
hasBytesAvailable
Returns `YES` if the receiver has bytes available to read. The receiver may also return `YES` if a read must be attempted in order to determine the availability of bytes.
initWithData:
data
Returns an initialized NSInputStream object for reading from data.
initWithFileAtPath:
path
Returns an initialized NSInputStream object for reading from the file at the specified path.
initWithURL:
url
Returns an initialized NSInputStream object for reading from the specified URL.
read:
buffer
maxLength:
len
Reads up to len bytes into buffer, returning the actual number of bytes read.
Software documentation for the NSOutputStream class
Foundation/NSStream.h
NSOutputStream is a subclass of NSStream that provides write-only stream functionality.
outputStreamToBuffer:
buffer
capacity:
capacity
Creates and returns an initialized NSOutputStream object that can write to buffer, up to a maximum of capacity bytes.
outputStreamToFileAtPath:
path
append:
shouldAppend
Creates and returns an initialized NSOutputStream object for writing to the file specified by path.
outputStreamToMemory
Creates and returns an initialized NSOutputStream object that will write stream data to memory.
hasSpaceAvailable
Returns `YES` if the receiver can be written to, or if a write must be attempted in order to determine if space is available.
initToBuffer:
buffer
capacity:
capacity
Returns an initialized NSOutputStream object that can write to buffer, up to a maximum of capacity bytes.
initToFileAtPath:
path
append:
shouldAppend
Returns an initialized NSOutputStream object for writing to the file specified by path.
If shouldAppend is `YES`, newly written data will be appended to any existing file contents.
initToMemory
Returns an initialized NSOutputStream object that will write to memory.
write:
buffer
maxLength:
len
Writes the contents of buffer, up to a maximum of len bytes, to the receiver.
Software documentation for the NSStream class
Foundation/NSStream.h
NSStream is an abstract class for objects representing streams.
getStreamsToHost:
host
port:
port
inputStream:
inputStream
outputStream:
outputStream
Creates and returns by reference an NSInputStream object and NSOutputStream object for a socket connection with the specified port on host.
close
Closes the receiver.
Repeated calls to this method on the same stream are quietly ignored.
delegate
Returns the receiver's delegate.
open
Opens the receiving stream.
Upon completion of the open operation, an NSStreamEventOpenCompleted event is sent to the recevier's delegate.
Repeated calls to this method on the same stream are quietly ignored.
propertyForKey:
key
Returns the receiver's property for the specified key.
removeFromRunLoop:
aRunLoop
forMode:
mode
Removes the receiver from the NSRunLoop specified by aRunLoop running in the mode.
Attempts to remove the receiver from a run loop or a mode in which it has not been scheduled are quietly ignored.
scheduleInRunLoop:
aRunLoop
forMode:
mode
Schedules the receiver on aRunLoop using the specified mode.
You must not attempt to add a stream to more than one run loop, but you may call this method multiple times to add the receiver in different modes for the same run loop.
setDelegate:
delegate
Sets the receiver's delegate.
setProperty:
property
forKey:
key
Sets the value of the property specified by key to property, returns `YES` if the key-value pair are accepted by the receiver.
streamError
Returns an NSError object representing the stream error, or `nil` if no error has been encountered.
streamStatus
Returns the receiver's status.
Software documentation for the NSObject(NSStreamDelegate) informal protocol
Foundation/NSStream.h
Informal protocol for delegates of instance of the NSStream class.
stream:
sStream
handleEvent:
anEvent
Description forthcoming.
Software documentation for the NSStreamDelegate protocol
Foundation/NSStream.h
NSObject
Description forthcoming.
stream:
sStream
handleEvent:
anEvent
Description forthcoming.