byte-streams

The byte-streams module provides streams for reading and writing bytes.

API Reference

Classes

ByteReader

Constructors
ByteReader(inputStream)

Creates a binary input stream that reads bytes from a backing stream.

inputStream : stream

The backing stream, an nsIInputStream.

Methods
close()

Closes both the stream and its backing stream. If the stream is already closed, an exception is thrown.

read(numBytes)

Reads a string from the stream. If the stream is closed, an exception is thrown.

[ numBytes : number ]

The number of bytes to read. If not given, the remainder of the entire stream is read.

Returns: string

A string containing the bytes read. If the stream is at the end, returns the empty string.

Properties
closed : boolean

True if the stream is closed.

ByteWriter

Constructors
ByteWriter(outputStream)

Creates a binary output stream that writes bytes to a backing stream.

outputStream : stream

The backing stream, an nsIOutputStream.

Methods
close()

Closes both the stream and its backing stream. If the stream is already closed, an exception is thrown.

write(str)

Writes a string to the stream. If the stream is closed, an exception is thrown.

str : string

The string to write.

Properties
closed : boolean

True if the stream is closed.