Add documentation and checking to pack streams, return the number of bytes (un)packed.