[Twisted-Python] Serving a binary files from disk, outside folders for static content

Thomas Weholt 2002 at weholt.org
Thu Feb 27 16:59:26 EST 2003

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 :

request.setContentType( .... content-type set based on extension of file to serve )
f = open(somefile)
while 1:
    d = f.read(2048) # what's the correct size to read
    if not d:

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.

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.

Best regards,
Thomas Weholt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030227/8efaf712/attachment.htm 

More information about the Twisted-Python mailing list