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