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)
|
self.ensure_directory_exists(file_dir_path)
|
||||||
|
|
||||||
if overwrite or not os.path.exists(full_file_path):
|
if overwrite or not os.path.exists(full_file_path):
|
||||||
with open(
|
if isinstance(data, str):
|
||||||
full_file_path,
|
with open(full_file_path, mode="w", encoding="utf-8", newline="\n") as file:
|
||||||
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:
|
|
||||||
file.write(data)
|
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()
|
file.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,18 +70,18 @@ class S3FileStorage(Storage):
|
||||||
if overwrite or not await self.file_exists(file_path):
|
if overwrite or not await self.file_exists(file_path):
|
||||||
|
|
||||||
def save_data_to_file():
|
def save_data_to_file():
|
||||||
with self.s3.open(
|
if isinstance(data, str):
|
||||||
full_file_path,
|
with self.s3.open(
|
||||||
mode="w" if isinstance(data, str) else "wb",
|
full_file_path, mode="w", encoding="utf-8", newline="\n"
|
||||||
encoding="utf-8" if isinstance(data, str) else None,
|
) as file:
|
||||||
) as file:
|
|
||||||
if hasattr(data, "read"):
|
|
||||||
data.seek(0)
|
|
||||||
file.write(data.read())
|
|
||||||
else:
|
|
||||||
file.write(data)
|
file.write(data)
|
||||||
|
else:
|
||||||
file.close()
|
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)
|
await run_async(save_data_to_file)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue