Check that the 'written' parameter in this function is non-null before incrementing it by 'written_chunk'.