[Zope] python: file size screw up????

Aseem Mohanty aseem@neurobehavioralsystems.com
Tue, 30 Jul 2002 04:43:00 -0700


Hi,
I am creating a zip file on the fly on the local file system and sending 
it back to the browser via an external method. This the following that I 
do for that (thanks to Jan and Chris M.):

    zip_size = stat(zip_file_name+'.zip')[ST_SIZE]
    zip_file = open(zip_file_name+'.zip')
    zip_data = zip_file.read()
    zip_file.close()      

    REQUEST.RESPONSE.setStatus('OK')
    REQUEST.RESPONSE.setHeader('Content-Type','application/zip')
    REQUEST.RESPONSE.setHeader('Content-Length',zip_size)
    REQUEST.RESPONSE.setHeader('Content-Disposition','inline; 
filename='+project_name+'.zip')
    return zip_data

Everything works perfectly .... EXCEPT :

the file size, when I look up up the properties of the downloaded file, 
it says its 595 bytes in size but size on disk is 4K (which is 
correct)... Of course since the file size is screwed up my zip utility 
goes nuts!!! After some minor tinkering I found that...

the stat.ST_SIZE is not the same as len(zip_file.read())
stat.ST_SIZE = 4k (correct)
len(zip_file.read()) = 595 b (why ... oh why...)

what is going on here?? shouldnt they be the same?? any pointers .... 
anybody??
TIA
AM

-- 
==================================================================
 Aseem Mohanty							   
 Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 
 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231		  	
==================================================================								  	
 "I saw `cout' being shifted "Hello world" times to the left and  
  stopped right there!!"                        -- Steve Gonedes  
==================================================================