1 from zlib import compress, decompress
3 from django.core.files.base import ContentFile, File
4 from django.core.files.storage import FileSystemStorage
5 from django.utils.deconstruct import deconstructible
9 class GzipFileSystemStorage(FileSystemStorage):
10 def _open(self, name, mode='rb'):
11 """TODO: This is good for reading; what about writing?"""
12 f = open(self.path(name), 'rb')
15 return ContentFile(decompress(text))
17 def _save(self, name, content):
18 content = ContentFile(compress(content.read()))
20 return super(GzipFileSystemStorage, self)._save(name, content)