Seeking

Most stream operations simply advance the stream pointer as the stream is read. The current stream position can always be obtained using fz_tell (deliberately similar to the standard ftell call):


\begin{lstlisting}
/*
fz_tell: return the current reading position within a stream
*/
int64_t fz_tell(fz_context *ctx, fz_stream *stm);
\end{lstlisting}

Some streams allow you to seek within them, that is, to change the current stream pointer to a given offset. To do this, use fz_seek (deliberately similar to fseek):


\begin{lstlisting}
/*
fz_seek: Seek within a stream.
\par
stm: The stream to se...
...k(fz_context *ctx, fz_stream *stm, int64_t offset, int whence);
\end{lstlisting}

In the event that a stream does not support seeking, an error will be thrown.

As fz_seek and fz_tell work at byte granularity, care should be exercised when reading streams bitwise. Always fz_sync_bits before expecting fz_tell to give you a value that you can safely fz_seek back to.