Fix incorrect comparison when shrinking buffer

During a write operation, the same buffer gets re-used for each chunk of
writing. If the number of points left to write is smaller than the
capacity of the buffer, we want to shrink the buffer down to size.
Unfortunately, there was a typo in that comparison (lt instead of gt) so
the buffer would never get shrunk.

This patch adds a test case to confirm the bug and provides a fix.