Skip to content

Commit

Permalink
fix: tmpfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoytovMA committed Apr 23, 2024
1 parent 76459c3 commit d32c711
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fsconnectors/utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(
self.mode = mode

def __enter__(self) -> 'SinglepartWriter':
self.file = tempfile.NamedTemporaryFile(self.mode)
self.file = tempfile.NamedTemporaryFile(f'{self.mode}+')
return self

def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
Expand All @@ -211,6 +211,7 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
if self.mode != 'wb':
data = data.encode('utf-8')
self.client.put_object(Body=data, Bucket=self.bucket, Key=self.key)
self.file.close()

def write(self, data: Union[str, bytes]) -> None:
self.file.write(data)
Expand Down Expand Up @@ -245,7 +246,7 @@ def __init__(
self.mode = mode

async def __aenter__(self) -> 'AsyncSinglepartWriter':
self.file = await asynctempfile.TemporaryFile(self.mode)
self.file = await asynctempfile.NamedTemporaryFile(f'{self.mode}+')
return self

async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
Expand All @@ -254,6 +255,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
if self.mode != 'wb':
data = data.encode('utf-8')
await self.client.put_object(Body=data, Bucket=self.bucket, Key=self.key)
await self.file.close()

async def write(self, data: Union[str, bytes]) -> None:
await self.file.write(data)
Expand Down

0 comments on commit d32c711

Please sign in to comment.