Helper methods to read binary data from an input stream.
State monad implementation to use when loading images.