(data, legacy=False)
return io.getvalue()
Prepare data for saving.
Prepare data for saving.
Prepare data for saving .
def prepare_file(data, legacy=False):
    """Prepare data for saving."""
    data['Time']['Modified'] = time.time()
    data['FileVersion'] = FILE_VERSION
    data['Version'] = VERSION
    
    if legacy:
        return zlib.compress(pickle.dumps(data, PICKLE_PROTOCOL))
    
    #Separate the maps from the main dictionary
    numpy_maps = IterateMaps(data['Resolution']).separate()
    
    #Write the maps to a zip file in memory
    io = BytesIO()
    with CustomOpen(io, 'w') as f:
        f.write(pickle.dumps(dict(data), PICKLE_PROTOCOL), 'data.pkl')
        
        #Write metadata for quick access
        f.write(str(VERSION), 'metadata\\version.txt')
        f.write(str(FILE_VERSION), 'metadata\\file.txt')
        f.write(str(data['Time']['Modified']), 'metadata/modified.txt')
        f.write(str(data['Time']['Created']), 'metadata/created.txt')
        f.write(str(data['TimesLoaded']), 'metadata/sessions.txt')
        f.write(str(data['Ticks']['Total']), 'metadata/time.txt')
        
        #Pickle the numpy map, or load it raw if not edited
        for i, m in enumerate(numpy_maps):
            if isinstance(m, numpy.LazyLoader) and m.is_loaded:
                m = m.pop()
            if isinstance(m, numpy.LazyLoader):
                f.write(m.pop(raw=True), 'maps/{}.npy'.format(i))
            else:
                f.write(numpy.save(m), 'maps/{}.npy'.format(i))
    
    #Undo the modify
    IterateMaps(data['Resolution']).join(numpy_maps)
    
    return io.getvalue()
def prepare_file ( data , legacy = False ) : data [ 'Time' ] [ 'Modified' ] = time . time ( ) data [ 'FileVersion' ] = FILE_VERSION data [ 'Version' ] = VERSION if legacy : return zlib . compress ( pickle . dumps ( data , PICKLE_PROTOCOL ) ) #Separate the maps from the main dictionary numpy_maps = IterateMaps ( data [ 'Resolution' ] ) . separate ( ) #Write the maps to a zip file in memory io = BytesIO ( ) with CustomOpen ( io , 'w' ) as f : f . write ( pickle . dumps ( dict ( data ) , PICKLE_PROTOCOL ) , 'data.pkl' ) #Write metadata for quick access f . write ( str ( VERSION ) , 'metadata\\version.txt' ) f . write ( str ( FILE_VERSION ) , 'metadata\\file.txt' ) f . write ( str ( data [ 'Time' ] [ 'Modified' ] ) , 'metadata/modified.txt' ) f . write ( str ( data [ 'Time' ] [ 'Created' ] ) , 'metadata/created.txt' ) f . write ( str ( data [ 'TimesLoaded' ] ) , 'metadata/sessions.txt' ) f . write ( str ( data [ 'Ticks' ] [ 'Total' ] ) , 'metadata/time.txt' ) #Pickle the numpy map, or load it raw if not edited for i , m in enumerate ( numpy_maps ) : if isinstance ( m , numpy . LazyLoader ) and m . is_loaded : m = m . pop ( ) if isinstance ( m , numpy . LazyLoader ) : f . write ( m . pop ( raw = True ) , 'maps/{}.npy' . format ( i ) ) else : f . write ( numpy . save ( m ) , 'maps/{}.npy' . format ( i ) ) #Undo the modify IterateMaps ( data [ 'Resolution' ] ) . join ( numpy_maps ) return io . getvalue ( )