<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def data_size(metadata):
 """ Calculate the size of a torrent based on parsed metadata. """

    info = metadata['info']

    if 'length' in info:
        # Single file
        total_size = info['length']
    else:
        # Directory structure
        total_size = sum([f['length'] for f in info['files']])

    return total_size