Skip to content

Conversation

@kumaraditya303
Copy link
Contributor

No description provided.

if path:
with open(path, "w") as f:
json.dump(result, f)
await async_writefile(path, "w", json.dumps(result))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was already leaving this comment, should be async_write_file(page, json.dumps(result))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay but how would you write in binary with this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OR you mean we should have two functions for writing one for str and one for bytes ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_write_file would accept Union[str, bytes] and will pick the right mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Thanks for confirming

if not isinstance(storageState, dict):
with open(storageState, "r") as f:
params["storageState"] = json.load(f)
params["storageState"] = json.loads(await async_read_text(storageState))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(await async_read_file()).decode()

make_dirs_for_file(path)
with open(path, "wb") as fd:
fd.write(decoded_binary)
await async_writefile(path, "wb", decoded_binary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

file_payloads.append(
{
"name": os.path.basename(item),
"buffer": base64.b64encode(await async_read_binary(item)).decode(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_read_file

await loop.run_in_executor(None, inner)


async def async_read_binary(file: Union[str, Path]) -> bytes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_read_file



async def async_read_text(file: Union[str, Path]) -> str:
return (await async_read_binary(file)).decode()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline this, no reason to have a separate function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@pavelfeldman pavelfeldman merged commit f9abeae into microsoft:master Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants