A stream of bytes, which can be read or written. More...
#import <Foundation/Foundation.h>


Instance Methods | |
| (id) | - initWithString: |
| Initializes a stream which reads from a string. More... | |
| (id) | - initWithCapacity: |
| Initializes a stream which reads and writes memory, and starts empty. | |
| (id) | - initWithBytes:length: |
| Initializes a stream which reads and writes a copy of some bytes, from the start. | |
| (id) | - initWithStream: |
| Initializes a stream with one from picofuse, which is closed when this is, or if this returns nil. More... | |
| (int) | - peek |
| Returns the next byte, without reading it, or NXStreamEnd if there isn't one at present. | |
| (size_t) | - readBytes:length: |
| Reads bytes. More... | |
| (NXString *) | - readStringWithLength: |
| Reads a string. More... | |
| (size_t) | - writeBytes:length: |
| Writes bytes. More... | |
| (size_t) | - writeString: |
| Writes a string. More... | |
| (NXString *) | - hashWithAlgorithm: |
| Reads the rest of the stream, and returns a hash of it. More... | |
| (size_t) | - hashWithAlgorithm:bytes: |
| Reads the rest of the stream, and returns a hash of it, as bytes. More... | |
| (size_t) | - position |
| Returns the position from the start, or NXNotFound if the stream doesn't have one. | |
| (BOOL) | - seek:relative: |
| Changes the position. More... | |
| (BOOL) | - isEnded |
| Returns YES if there'll never be anything else to read, as when a network connection has been closed, or the stream has. More... | |
| (void) | - close |
| Closes the stream, which can't be used after that. More... | |
| (BOOL) | - isClosed |
| Returns YES if the stream has been closed. | |
Instance Methods inherited from NXObject | |
| (void) | - dealloc |
| Frees the instance. More... | |
| (NXZone *) | - zone |
| Returns the zone in which the instance was allocated. More... | |
| (id) | - retain |
| Increases the retain count of the receiver. More... | |
| (void) | - release |
| Decreases the retain count of the receiver. More... | |
| (id) | - autorelease |
| Releases the receiver later, when the current autorelease pool of the thread is drained. More... | |
| (id) | - copy |
| Returns a copy which can't be changed by anything else, which the caller owns and has to release. More... | |
| (uintptr_t) | - hash |
| Returns a number for the object, which is the same for objects which are equal by isEqual:. More... | |
| (NXString *) | - description |
| Returns a string which describes the instance, for logging. More... | |
Instance Methods inherited from Object | |
| (id) | - init |
| Initialize the instance, after allocation. More... | |
| (Class) | - class |
| Returns the class of the instance. More... | |
| (Class) | - superclass |
| Returns the superclass of the instance. More... | |
| (BOOL) | - isEqual: |
| Compares the receiver to another object for equality. More... | |
| (BOOL) | - isKindOfClass: |
| Returns a Boolean value that indicates whether the receiver is an instance of a given class. More... | |
| (BOOL) | - conformsTo: |
| Checks if the receiver's class conforms to a protocol. More... | |
Instance Methods inherited from <ObjectProtocol> | |
| (BOOL) | - respondsToSelector: |
| Checks if the receiver responds to a selector. More... | |
Class Methods | |
| (id) | + streamWithString: |
| Returns a stream which reads from a string. More... | |
| (id) | + streamWithCapacity: |
| Returns a stream which reads and writes memory, and starts empty. More... | |
| (id) | + streamWithBytes:length: |
| Returns a stream which reads and writes a copy of some bytes, from the start. More... | |
| (id) | + streamWithData: |
| Returns a stream which reads and writes a copy of the bytes of data, from the start. More... | |
| (NXStream *) | + standardInput |
| Returns a stream for the standard input, or nil if there isn't one. | |
| (NXStream *) | + standardOutput |
| Returns a stream for the standard output, or nil if there isn't one. | |
Class Methods inherited from NXObject | |
| (id) | + alloc |
| Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More... | |
| (id) | + allocWithZone: |
| Allocates a new instance in a specific zone. More... | |
| (id) | + new |
| Allocates and initializes a new instance, as [[cls alloc] init] does. More... | |
| (NXString *) | + description |
| Returns the name of the class. | |
Class Methods inherited from Object | |
| (void) | + initialize |
| Performs one-time initialization for the class. More... | |
| (Class) | + class |
| Returns the class object. More... | |
| (Class) | + superclass |
| Returns the superclass of the class. More... | |
| (const char *) | + name |
| Returns the name of the class. More... | |
| (BOOL) | + conformsTo: |
| Checks if the class conforms to a protocol. More... | |
Additional Inherited Members | |
Protected Attributes inherited from Object | |
| Class | isa |
| A pointer to the object's class structure. More... | |
A stream of bytes, which can be read or written.
A stream reads from a string, reads and writes memory, is the standard input or output of the program, or is any other stream of picofuse. Some streams have a position, which can be changed.
Reading and writing return how many bytes could be read or written at the time, which may be fewer than were asked for, or none. Some streams wait until there's something to read, such as the standard input on a Mac or Linux.
There's a limit to how many streams can be open at once (SYS_IOSTREAM_CAPACITY), which includes the standard input and output, so close them once they're no longer needed, if they might not be deallocated soon.
A stream is used by one thread at a time. Streams of the standard input share a byte which has been peeked at, so only one thread reads the standard input. See Threads and mutable objects.
Definition at line 38 of file NXStream.h.
| - (void) close |
Closes the stream, which can't be used after that.
Standard input and output aren't themselves closed. It's closed when it's deallocated, if it hasn't been.
| - (NXString *) hashWithAlgorithm: | (NXHashAlgorithm) | algorithm |
Reads the rest of the stream, and returns a hash of it.
This reads until a read returns nothing. Unlike readStringWithLength:, that means the standard input on Mac and Linux, or a pipe, is read until it's closed, which may never happen. If the stream has a position, it's then at the end.
| - (size_t) hashWithAlgorithm: | (NXHashAlgorithm) | algorithm | |
| bytes: | (void *) | bytes | |
Reads the rest of the stream, and returns a hash of it, as bytes.
| algorithm | The algorithm. |
| bytes | Where to put the hash, which can be up to NXHashMaxSize bytes. |
| - (id) initWithStream: | (sys_iostream_t *) | stream |
Initializes a stream with one from picofuse, which is closed when this is, or if this returns nil.
It returns nil if that's NULL.
Initializes a stream which reads from a string.
If it's an NXMutableString, it can be changed without affecting the stream.
| - (BOOL) isEnded |
Returns YES if there'll never be anything else to read, as when a network connection has been closed, or the stream has.
It's NO at the end of a string or memory, as the position can be changed. To find out if there's anything to read at present, use peek.
| - (size_t) readBytes: | (void *) | bytes | |
| length: | (size_t) | length | |
Reads bytes.
| bytes | Where to put what's read. |
| length | The most bytes to read. |
| - (NXString *) readStringWithLength: | (size_t) | length |
Reads a string.
| length | The most bytes to read. A character may be split, if it's more than one. |
Changes the position.
| offset | The number of bytes from the start, or from the position if relative, in which case it's backwards if negative. |
| relative | YES if it's from the position, or NO if it's from the start. |
| + (id) streamWithBytes: | (const void *) | bytes | |
| length: | (size_t) | length | |
Returns a stream which reads and writes a copy of some bytes, from the start.
| bytes | The bytes, which can include zero, or NULL if the length is zero. |
| length | The number of bytes, which is also the most that can be written. |
| + (id) streamWithCapacity: | (size_t) | capacity |
Returns a stream which reads and writes memory, and starts empty.
| capacity | The most bytes that can be written. |
Returns a stream which reads and writes a copy of the bytes of data, from the start.
Returns a stream which reads from a string.
| - (size_t) writeBytes: | (const void *) | bytes | |
| length: | (size_t) | length | |
Writes bytes.
| - (size_t) writeString: | (NXString *) | string |
Writes a string.