fix: handle newlines explicitly when storing files
This commit is contained in:
parent
c7d0f64cb1
commit
eee39b238b
2 changed files with 20 additions and 20 deletions
|
|
@ -82,16 +82,16 @@ class LocalFileStorage(Storage):
|
|||
self.ensure_directory_exists(file_dir_path)
|
||||
|
||||
if overwrite or not os.path.exists(full_file_path):
|
||||
with open(
|
||||
full_file_path,
|
||||
mode="w" if isinstance(data, str) else "wb",
|
||||
encoding="utf-8" if isinstance(data, str) else None,
|
||||
) as file:
|
||||
if hasattr(data, "read"):
|
||||
data.seek(0)
|
||||
file.write(data.read())
|
||||
else:
|
||||
if isinstance(data, str):
|
||||
with open(full_file_path, mode="w", encoding="utf-8", newline="\n") as file:
|
||||
file.write(data)
|
||||
else:
|
||||
with open(full_file_path, mode="wb") as file:
|
||||
if hasattr(data, "read"):
|
||||
data.seek(0)
|
||||
file.write(data.read())
|
||||
else:
|
||||
file.write(data)
|
||||
|
||||
file.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -70,18 +70,18 @@ class S3FileStorage(Storage):
|
|||
if overwrite or not await self.file_exists(file_path):
|
||||
|
||||
def save_data_to_file():
|
||||
with self.s3.open(
|
||||
full_file_path,
|
||||
mode="w" if isinstance(data, str) else "wb",
|
||||
encoding="utf-8" if isinstance(data, str) else None,
|
||||
) as file:
|
||||
if hasattr(data, "read"):
|
||||
data.seek(0)
|
||||
file.write(data.read())
|
||||
else:
|
||||
if isinstance(data, str):
|
||||
with self.s3.open(
|
||||
full_file_path, mode="w", encoding="utf-8", newline="\n"
|
||||
) as file:
|
||||
file.write(data)
|
||||
|
||||
file.close()
|
||||
else:
|
||||
with self.s3.open(full_file_path, mode="wb") as file:
|
||||
if hasattr(data, "read"):
|
||||
data.seek(0)
|
||||
file.write(data.read())
|
||||
else:
|
||||
file.write(data)
|
||||
|
||||
await run_async(save_data_to_file)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue