cyberdelia/django-pipeline — pull request #63 by adamcharnock (2012-01-06 13:12:15+00:00)
Title: Fixing an issue when for files which contain unicode data

The django.core.files.base module uses the cStringIO package where available. However, unlike StringIO, cStringIO does not support unicode data, and the result is additional null bytes being entered into the output file.

The trick seems to be to convert the data into a byte string before passing it into ContentFile, which I do here using Django's smart_str() utility.