The onWikiAttachment method of the XAROutputWikiStream uses a 4096 byte size buffer to convert the input stream for the attachment to the XAR output stream.
However to base64-enocode the stream, separate calls to Base64.encodeBase64String(buffer) are made. This utility assumes the input of every chunk is all there is to encode, and pads the results in a way that is interpreted as EOF when base64 decoding.
Effectively, while the contents of the attachment are streamed out completely to the output, the stream is interrupted by EOF-markers every 4096 bytes, causing the attachment to look only 4096 bytes long when e.g. importing als XAR.
Workaround: use a buffer size which is a multiple of 3 (e.g. 4095), which does not need padding the chunked results when base64 encoding.