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
6 from django.utils.encoding import force_bytes
10 class GzipFileSystemStorage(FileSystemStorage):
11 def _open(self, name, mode='rb'):
12 """TODO: This is good for reading; what about writing?"""
13 f = open(self.path(name), 'rb')
16 return ContentFile(decompress(text))
18 def _save(self, name, content):
19 data = force_bytes(content.read())
20 content = ContentFile(compress(data))
22 return super(GzipFileSystemStorage, self)._save(name, content)