picofuse-objc

Instance Methods | Class Methods | List of all members
NXStream Class Reference

A stream of bytes, which can be read or written. More...

#import <Foundation/Foundation.h>

Inheritance diagram for NXStream:
Inheritance graph
[legend]
Collaboration diagram for NXStream:
Collaboration graph
[legend]

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...
 

Detailed Description

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.

Method Documentation

◆ close()

- (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.

◆ hashWithAlgorithm:()

- (NXString *) hashWithAlgorithm: (NXHashAlgorithm)  algorithm

Reads the rest of the stream, and returns a hash of it.

Returns
The hash, in lowercase hexadecimal, or nil if it isn't available or there isn't enough memory.

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.

◆ hashWithAlgorithm:bytes:()

- (size_t) hashWithAlgorithm: (NXHashAlgorithm)  algorithm
bytes: (void *)  bytes 

Reads the rest of the stream, and returns a hash of it, as bytes.

Parameters
algorithmThe algorithm.
bytesWhere to put the hash, which can be up to NXHashMaxSize bytes.
Returns
The size of the hash, or zero if it isn't available.

◆ initWithStream:()

- (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.

◆ initWithString:()

- (id) initWithString: (NXString *)  string

Initializes a stream which reads from a string.

If it's an NXMutableString, it can be changed without affecting the stream.

◆ isEnded()

- (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.

◆ readBytes:length:()

- (size_t) readBytes: (void *)  bytes
length: (size_t)  length 

Reads bytes.

Parameters
bytesWhere to put what's read.
lengthThe most bytes to read.
Returns
The number of bytes read, which is zero if there are none at present.

◆ readStringWithLength:()

- (NXString *) readStringWithLength: (size_t)  length

Reads a string.

Parameters
lengthThe most bytes to read. A character may be split, if it's more than one.
Returns
The string, or nil if there's nothing to read at present or there isn't enough memory. It stops at the first zero byte, although more may have been read. It may be shorter than there is to read, if the stream doesn't have a position.

◆ seek:relative:()

- (BOOL) seek: (ptrdiff_t)  offset
relative: (BOOL)  relative 

Changes the position.

Parameters
offsetThe number of bytes from the start, or from the position if relative, in which case it's backwards if negative.
relativeYES if it's from the position, or NO if it's from the start.
Returns
YES if successful, or NO if the stream doesn't have a position, or it's before the start or beyond the end, in which case it's not changed.

◆ streamWithBytes:length:()

+ (id) streamWithBytes: (const void *)  bytes
length: (size_t)  length 

Returns a stream which reads and writes a copy of some bytes, from the start.

Parameters
bytesThe bytes, which can include zero, or NULL if the length is zero.
lengthThe number of bytes, which is also the most that can be written.
Returns
The stream, or nil if too many are open or there isn't enough memory.

◆ streamWithCapacity:()

+ (id) streamWithCapacity: (size_t)  capacity

Returns a stream which reads and writes memory, and starts empty.

Parameters
capacityThe most bytes that can be written.
Returns
The stream, or nil if too many are open or there isn't enough memory.

◆ streamWithData:()

+ (id) streamWithData: (NXData *)  data

Returns a stream which reads and writes a copy of the bytes of data, from the start.

Returns
The stream, or nil if too many are open or there isn't enough memory.

◆ streamWithString:()

+ (id) streamWithString: (NXString *)  string

Returns a stream which reads from a string.

Returns
The stream, or nil if too many are open or there isn't enough memory.

◆ writeBytes:length:()

- (size_t) writeBytes: (const void *)  bytes
length: (size_t)  length 

Writes bytes.

Returns
The number of bytes written, which may be fewer than the length, or zero if the stream can't be written.

◆ writeString:()

- (size_t) writeString: (NXString *)  string

Writes a string.

Returns
The number of bytes written, which may be fewer than its length.

The documentation for this class was generated from the following file: