write dynamic number of bytes