1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import gzip, FuseArchive, logging, cPickle
gzip_compress_level = 6
class Serializer:
"""This lets us experiment with different main file serializers"""
@staticmethod
def dump( f, obj ):
out = open( f, "wb" )
Serializer.dumpfh( obj, out ) # new file format
out.close()
@staticmethod
def dumpfh( fh, obj ):
logging.debug( "Going to serialize %s to %s" % ( obj, fh ) )
fh.truncate( 0 )
fh.seek( 0 )
f = gzip.GzipFile( None, "wb", gzip_compress_level, fh )
#f = fh
cPickle.dump( obj, f, -1 )
del f
fh.flush()
@staticmethod
def load( f ):
if FuseArchive.magic_profiling:
return { 'size': 0, 'chunks': 0, 'chunk_size': 0 }
inp = open( f, "rb" )
magic = Serializer.loadfh( inp )
inp.close()
return magic
@staticmethod
def loadfh( fh ):
logging.debug( "Going to load from %s" % fh )
fh.seek( 0 )
f = gzip.GzipFile( None, "rb", gzip_compress_level, fh )
#f = fh
magic = cPickle.load( f )
return( magic )
|