File wrappers¶
A view return DownloadResponse
which
itself carries a file wrapper. Here are file wrappers distributed by Django
and django-downloadview.
Django’s builtins¶
Django itself provides some file wrappers [1] you can use within
django-downloadview
:
django.core.files.File
wraps a file that live on local filesystem, initialized with a path.django-downloadview
uses this wrapper in PathDownloadView.django.db.models.fields.files.FieldFile
wraps a file that is managed in a model.django-downloadview
uses this wrapper in ObjectDownloadView.django.core.files.base.ContentFile
wraps a bytes, string or unicode object. You may use it with VirtualDownloadView.
django-downloadview builtins¶
django-downloadview
implements additional file wrappers:
StorageFile
wraps a file that is managed via a storage (but not necessarily via a model). StorageDownloadView uses this wrapper.HTTPFile
wraps a file that lives at some (remote) location, initialized with an URL. HTTPDownloadView uses this wrapper.VirtualFile
wraps a file that lives in memory, i.e. built as a string. This is a convenient wrapper to use in VirtualDownloadView subclasses.
Low-level IO utilities¶
django-downloadview provides two classes to implement file-like objects whose content is dynamically generated:
TextIteratorIO
for generated text;BytesIteratorIO
for generated bytes.
These classes may be handy to serve dynamically generated files. See VirtualDownloadView for details.
Tip
Text or bytes? (formerly “unicode or str?”) As django-downloadview is meant to serve files, as opposed to read or parse files, what matters is file contents is preserved. django-downloadview tends to handle files in binary mode and as bytes.