def test_gzip_compress(self): compressed_data = gzip_compress(b'hello world') # test gzip magic self.assertEqual(compressed_data[:2], GZIP_MAGIC) self.assertEqual(gzip_decompress(compressed_data), b'hello world')
def load_remote(self, key): data = key.get_contents_as_string() if key.content_encoding == 'gzip' or data.startswith(GZIP_MAGIC): data = gzip_decompress(data) data = data.decode("ascii") objects = data.split("\n") self.objects.update(objects) log.info("loaded %i old objects from %s/%s", len(objects), self.bucket.name, self.keyname)
def test_compress_stream(self): src = BytesIO(b"hello world") dst = BytesIO() compress_stream(src, dst) compressed_data = dst.getvalue() # test gzip magic self.assertEqual(compressed_data[:2], GZIP_MAGIC) self.assertEqual(gzip_decompress(compressed_data), b'hello world')
def test_save(self): conn = boto.connect_s3() bucket = conn.create_bucket('test-bucket') o = ObjectList(bucket) o.add("hash1") o.save() key = bucket.get_key(o.keyname) data = key.get_contents_as_string() data = gzip_decompress(data) self.assertEqual(data, b'hash1')
def load(self, input_file): """ Loads a manifest from a file object Arguments: input_file (file_object): the file object to read the manifest from """ data = input_file.read() if data.startswith(GZIP_MAGIC): data = gzip_decompress(data) data = data.decode("utf8") for h, filename, perms in json.loads(data): self.add(h, filename, perms)
def test_gzip_decompress(self): data = gzip_decompress(HELLO_WORLD) self.assertEqual(data, b'hello world')