Realised that I can use my cfile structure as the pointer to the private
structure data, rather than casting from void.
CFile buffer uses cfile structure as pointer for opaque private data,
as used everywhere else.
We need to know whether we're decoding or encoding, as it changes how we
use our buffer and how we initialise the xz_stream structure.

In other good news, the xz source details how to find the uncompressed size
of an xz file.  It's a bit convoluted, as it deals with reading one or more
footers (since xz files can be concatenated), but it saves us the ugliness
of what we do with bzip2.
Detect errors in lzma_code and fail at that point.

We now write full buffers correctly.  When the buffer is full -
i.e. avail_out == 0:
 1: Write the current buffer.
 2: Reset the output buffer pointer and signal available space.
 3: call lzma_code again.
 4: If avail_out == 0 again, loop back to 1

This minimises the number of file writes, and makes the process
read driven: i.e. the main for loop in encode could be extracted
as a single function call with a string buffer to write.  That's
what I want for the xz lib, so that's progress.
As proof of concept, moved write code into separate function to demonstrate
that the writing process can work correctly without needing to skip reads
in the loop as the sample code does.
Move buffer allocation above compression init so we can set up our
lzma struct pointers to the buffer.

Main routine of xz_write finished.  Give it the data, then run
lzma_code.  If the buffer is full, write data from it to the file until
the buffer has space again.