def load_index(self):
try:
resp = self.boto.get_object(
Bucket=self.bucket,
Key=self.index_path(),
)
body = resp['Body'].read()
content_type = magic.from_buffer(body, mime=True)
if content_type == 'text/plain':
logger.debug('Detected plain text encoding for index')
return json.loads(body.decode('utf-8'))
elif content_type == 'application/zlib':
logger.debug('Detected zlib encoding for index')
body = zlib.decompress(body)
return json.loads(body.decode('utf-8'))
elif content_type == 'application/x-empty':
return {}
else:
raise ValueError('Unknown content type for index', content_type)
except (ClientError):
return {}
评论列表
文章目录