dpapathanasiou wrote: > I have two methods for writing binaries files: the first works with > data received by a server corresponding to a file upload, and the > second works with data sent as email attachments.
Hmmm, no. Looking at your code, the first of your functions actually treats its argument as a stream, while the second one treats it like a byte buffer (as str object, to be precise). > The odd thing is, they're not interchangeable: if I use the first one > to saved data parsed from an email attachment, it fails; similarly, > the second function fails when dealing with an uploaded file data. There is nothing odd about that, they are different functions working with different things. > What are the critical differences? > > def write_binary_file (folder, filename, f, chunk_size=4096): [...] > for file_chunk in read_buffer(f, chunk_size): > file_obj.write(file_chunk) [...] > def write_binary_file (folder, filename, filedata): [...] > file_obj.write(filedata) BTW: You could have reduced the code yourself before posting. You might have seen the difference yourself then! Further, I'm curious, do you have any non-binary files anywhere? =) Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list