Exemplo n.º 1
0
def readMD(f, **kwargs):
	dats={}
	cat=f.read(16)
	while len(cat)==16:
		pl, hl, dl = struct.unpack("<IIQ", cat)
		path=f.read(pl)
		head=eval(f.read(hl))
		dat=None
		if dl:
			ct=f.read(1)
			if ct in ['<', '>', '|', "{"]:
				ct=ct+f.read(6)
				dti, nd = struct.unpack("<3sI", ct)
				if dti.startswith("{"):
					dti=dti[1:]
				dti=dtype(dti)
			else:
				print "warning, old mdat. May not be platform portable"
				nd = struct.unpack("<I", f.read(4))[0]
				dti=dtype("<"+ct)				
			sh=struct.unpack("<"+"Q"*nd, f.read(8*nd))
			dat=f.read(dl)
			dat=fromstring(dat, dti)
			dti=dti.str
			if DTS!=dti[0]:
				dtil=dtype(DTS+dti[1:])
				dat=dat.astype(dtil)
			dat=reshape(dat, sh)
		dats[path]=(dat, head)	
		cat=f.read(16)	
	try:
		url="file://%s" % (f.name,)
	except:
		try:
			url=f.geturl()
		except:
			url=None		
	if kwargs.get('return_raw_hash'):
		return dats	
	else:
		return hash2doc(dats, url)