Exemplo n.º 1
0
 async def head(self, ds_id: str, path: str = ''):
     key, local_path = self._get_key_and_local_path(ds_id, path)
     if _LOG_S3BUCKET_HANDLER:
         LOG.info(f'HEAD: key={key!r}, local_path={local_path!r}')
     if local_path is None or not local_path.exists():
         await self._key_not_found(key)
         return
     self.set_header('ETag', str_to_etag(str(local_path)))
     self.set_header('Last-Modified', mtime_to_str(local_path.stat().st_mtime))
     if local_path.is_file():
         self.set_header('Content-Length', local_path.stat().st_size)
     else:
         self.set_header('Content-Length', 0)
     await self.finish()
Exemplo n.º 2
0
 async def get(self, ds_id: str, path: str = ''):
     key, local_path = self._get_key_and_local_path(ds_id, path)
     if _LOG_S3BUCKET_HANDLER:
         LOG.info(f'GET: key={key!r}, local_path={local_path!r}')
     if local_path is None or not local_path.exists():
         await self._key_not_found(key)
         return
     self.set_header('ETag', str_to_etag(str(local_path)))
     self.set_header('Last-Modified', mtime_to_str(local_path.stat().st_mtime))
     self.set_header('Content-Type', 'binary/octet-stream')
     if local_path.is_file():
         self.set_header('Content-Length', local_path.stat().st_size)
         chunk_size = 1024 * 1024
         with open(str(local_path), 'rb') as fp:
             while True:
                 chunk = fp.read(chunk_size)
                 if len(chunk) == 0:
                     break
                 self.write(chunk)
                 await self.flush()
     else:
         self.set_header('Content-Length', 0)
         await self.finish()