aiopath icon indicating copy to clipboard operation
aiopath copied to clipboard

use buffer

Open hgalytoby opened this issue 1 year ago • 0 comments

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 avatar Aug 27 '22 06:08 hgalytoby