Example #1
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     zfile = GzipFile(mode="wb", compresslevel=6, fileobj=zbuf)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     content.file = zbuf
     content.seek(0)
     return content
Example #2
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     content.file = zbuf
     content.seek(0)
     return content
Example #3
0
File: ftp.py Project: BBKolton/ml4
 def _read(self, name):
     memory_file = BytesIO()
     try:
         pwd = self._connection.pwd()
         self._connection.cwd(os.path.dirname(name))
         self._connection.retrbinary('RETR ' + os.path.basename(name),
                                     memory_file.write)
         self._connection.cwd(pwd)
         memory_file.seek(0)
         return memory_file
     except ftplib.all_errors:
         raise FTPStorageException('Error reading file %s' % name)
Example #4
0
 def _read(self, name):
     memory_file = BytesIO()
     try:
         pwd = self._connection.pwd()
         self._connection.cwd(os.path.dirname(name))
         self._connection.retrbinary('RETR ' + os.path.basename(name),
                                     memory_file.write)
         self._connection.cwd(pwd)
         memory_file.seek(0)
         return memory_file
     except ftplib.all_errors:
         raise FTPStorageException('Error reading file %s' % name)
Example #5
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     # Boto 2 returned the InMemoryUploadedFile with the file pointer replaced,
     # but Boto 3 seems to have issues with that. No need for fp.name in Boto3
     # so just returning the BytesIO directly
     return zbuf
Example #6
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     # Boto 2 returned the InMemoryUploadedFile with the file pointer replaced,
     # but Boto 3 seems to have issues with that. No need for fp.name in Boto3
     # so just returning the BytesIO directly
     return zbuf
Example #7
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     #  The GZIP header has a modification time attribute (see http://www.zlib.org/rfc-gzip.html)
     #  This means each time a file is compressed it changes even if the other contents don't change
     #  For S3 this defeats detection of changes using MD5 sums on gzipped files
     #  Fixing the mtime at 0.0 at compression time avoids this problem
     zfile = GzipFile(mode="wb", compresslevel=6, fileobj=zbuf, mtime=0.0)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     content.file = zbuf
     content.seek(0)
     return content
Example #8
0
 def _compress_content(self, content):
     """Gzip a given string content."""
     zbuf = BytesIO()
     #  The GZIP header has a modification time attribute (see http://www.zlib.org/rfc-gzip.html)
     #  This means each time a file is compressed it changes even if the other contents don't change
     #  For S3 this defeats detection of changes using MD5 sums on gzipped files
     #  Fixing the mtime at 0.0 at compression time avoids this problem
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf, mtime=0.0)
     try:
         zfile.write(force_bytes(content.read()))
     finally:
         zfile.close()
     zbuf.seek(0)
     content.file = zbuf
     content.seek(0)
     return content