<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I need to serve a binary file from disk, not 
available in the normal folder for static content. In my code so far I've done 
something like this in the render-method :</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>request.setContentType( .... content-type set based 
on extension of file to serve )</FONT></DIV>
<DIV><FONT face=Arial size=2>f = open(somefile)</FONT></DIV>
<DIV><FONT face=Arial size=2>while 1:</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; d = f.read(2048) # what's the 
correct size to read</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; if not d:</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
break</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; request.write(d)</FONT></DIV>
<DIV><FONT face=Arial size=2>request.finish()</FONT></DIV>
<DIV><FONT face=Arial size=2>return</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>It seem to return the data OK, it's visible in the 
browser, but exceptions are raised in the server. How do I close this connection 
the right way? Should this be used with deferred or something like that? The 
files can be huge in size.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>PS! From recent postings in this list is seems as 
if Twisted doesn't support compression of content, using gzip etc. Is this true? 
This would speed up things considerably. I implemented this in my previous 
webserver-project using BaseHTTPServer and on big files the increase in speed 
was impressive. Compressing HTML/Plain text/XML etc., just files known to be 
based in plain text, would be a great start.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Best regards,</FONT></DIV>
<DIV><FONT face=Arial size=2>Thomas Weholt</FONT></DIV></BODY></HTML>