This document has a standard, validated CSS2 stylesheet, which your browser does not seem to display properly. In a browser supporting web standards, this table of contents would be fixed at the side of the page for easy reference.
anastigmatix homePrior to version 0.1 8, BinaryIO could fail in interpreters where the token operator does arbitrary read-ahead. If you have downloaded an earlier version, please replace it.
BinaryIO is a small resource providing procedures for reading and writing 8, 16, and 32 bit integers and 32 bit IEEE reals in big- or little-endian order, and for reading arrays of those types. Procedures to convert between a real and its 32 bit IEEE representation in an int are also provided.
BinaryIO
is a ProcSet
resource.
To make it available to your own code, include in the setup section of
your file:
/net.anastigmatix.BinaryIO /ProcSet findresource
The findresource
will succeed, leaving a dictionary on the
operand stack, if you have made
the
BinaryIO
resource file [download]
available in any of these ways:
findresource
(which belongs in the
setup section)%%DocumentNeededResources
and
%%IncludeResource
DSC comments, you include these comments at
the right position in your file to specify that it needs
net.anastigmatix.Order, your document manager software is configured to
automatically insert needed resources in files being printed, and you have
put the resource files where your document manager can find
them.
BinaryIO
relies on a few other resources, and you will need
those files also. If you use the first method, directly including resources in
your file's prolog, the prolog has to contain all of the needed resources, in
any order so long as no resource comes before one it depends on, and
categories come before resources that belong in them. Any of the other methods
should just work as long as all the files are where they need to be. These are
the resources you will need:
Resource | Category | Description |
---|---|---|
net.anastigmatix.MetaPre | ProcSet | Staged-programming extensions for PostScript |
net.anastigmatix.filter | Category | Category to contain filter resources usable with StreamIO. |
net.anastigmatix.StreamIO | ProcSet | I/O utilities and pure PostScript definable filters. |
net.anastigmatix.BinaryIO | ProcSet | The main attraction. |
The resource files are in a compact form. That is for efficiency, not to keep you from viewing them; there is a script for that on the resource packaging page.
The BinaryIO
dictionary may be placed on the lookup stack (with
begin
) for convenient access to the definitions in it, without
the bother of get
and exec
. The dictionary is
read-only, so before creating any
definitions, you will want either userdict begin
or your
own dict begin
so that you have a writable dictionary on top
of the dictionary stack.
This section describes the contents of the read-only dictionary that is
returned by /net.anastigmatix.BinaryIO /ProcSet findresource
.
The procedures that read always assume the required number of bytes can
be read, and will signal syntaxerror if not. (The exact contents of
the operand stack when syntaxerror is signalled may change as the
implementation evolves; see the
implementation note).
Converts the 32 bits contained in int, which must be in the form of a 32-bit IEEE 754 real, to a typed real. It is not necessarily possible to create an infinity or NaN with this procedure; those bit patterns in int may cause an error to be signalled.
Reads and returns an 8 bit signed integer.
Reads and returns an 8 bit unsigned integer. This is just like read except no boolean result is returned and syntaxerror is signalled if a byte cannot be read.
Reads and returns a 32 bit IEEE real stored highest byte first.
Reads and returns a 16 bit signed integer stored highest byte first.
Reads and returns a 32 bit signed integer stored highest byte first.
Reads and returns a 16 bit unsigned integer stored highest byte first.
Reads and returns a 32 bit IEEE real stored lowest byte first.
Reads and returns a 16 bit signed integer stored lowest byte first.
Reads and returns a 32 bit signed integer stored lowest byte first.
Reads and returns a 16 bit unsigned integer stored lowest byte first.
Fills string from file, signalling syntaxerror rather than returning a substring if too few bytes are read to fill the string.
Reads n consecutive 32 bit IEEE 754 reals stored highest byte first, and returns them in an array.
Reads n consecutive 16 bit signed integers stored highest byte first, and returns them in an array.
Reads n consecutive 32 bit signed integers stored highest byte first, and returns them in an array.
Reads n consecutive 16 bit unsigned integers stored highest byte first, and returns them in an array.
Reads n consecutive 32 bit IEEE 754 reals stored lowest byte first, and returns them in an array.
Reads n consecutive 16 bit signed integers stored lowest byte first, and returns them in an array.
Reads n consecutive 32 bit signed integers stored lowest byte first, and returns them in an array.
Reads n consecutive 16 bit unsigned integers stored lowest byte first, and returns them in an array.
Returns in int the IEEE 754 32-bit representation of real (whether or not the interpreter actually uses IEEE 754 as the internal form of real).
Writes a (signed or unsigned) 8 bit int onto file.
Writes real onto file as an IEEE 754 32-bit real, highest byte first.
Writes a (signed or unsigned) 16 bit int onto file, highest byte first.
Writes a 32 bit int onto file, highest byte first.
Writes real onto file as an IEEE 754 32-bit real, lowest byte first.
Writes a (signed or unsigned) 16 bit int onto file lowest byte first.
Writes a 32 bit int onto file, lowest byte first.
The aim of the implementation is to balance tolerable performance with small code size so that it is an easy decision to include the resource where it might be useful. I am not sure that the current approach is as good on either metric as I had intended, and I may try radically different approaches as time permits to see about improving it. To make any implementation changes as transparent as possible, the same API will be preserved, but there may be changes in the exact contents of the operand stack when syntaxerror is signalled.