Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use buffer #22

Open
hgalytoby opened this issue Aug 27, 2022 · 0 comments
Open

use buffer #22

hgalytoby opened this issue Aug 27, 2022 · 0 comments

Comments

@hgalytoby
Copy link

hgalytoby commented Aug 27, 2022

Receives bytes, but can also give to memoryview. (buffer.getbuffer() -> memoryview)

But pycharm will show a warning.

source code https://github.com/alexdelorenzo/aiopath/blob/main/aiopath/path.py#L180

# type-check for the buffer interface before truncating the file
view = memoryview(data)

I don't quite understand what this means.

I originally used getvalue, but after reading this https://stackoverflow.com/questions/61319551/when-should-one-use-bytesio-getvalue-instead-of-getbuffer, it seems that getbuffer would be better.

Everything works, it's just that I don't want pycharm to have a warning, I just want to know, thanks.

image

async def resize(path, size: Tuple[int, int] = (200, 200)):
    img = Image.open(path)
    buffer = io.BytesIO()
    if img.mode == 'P':
        img = img.convert('RGB')
    img.thumbnail(size=size)
    img.save(buffer, format=img.format.lower())
    await AsyncPath(path).write_bytes(buffer.getbuffer())
@hgalytoby hgalytoby changed the title buffer problem use buffer Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant