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

Is it possible to read from io.BytesIO? #19

Open
WaterKnight1998 opened this issue May 30, 2020 · 6 comments
Open

Is it possible to read from io.BytesIO? #19

WaterKnight1998 opened this issue May 30, 2020 · 6 comments

Comments

@WaterKnight1998
Copy link

I am going to use this util in Flask backend. However, I would like to use pims_nd2 in io.BytesIO.

Is it possible? Or should I save file locally?

@caspervdw
Copy link
Member

Hi,

Sorry, the open only works with actual file paths. As this project is merely wrapping the ND2 reading library from Nikon, we don’t have much control.

You could try virtual file systems if you want to stay in memory, but it depends on your OS how that works. I don’t have experience with that.

Or, try a pure Python alternative like https://github.com/rbnvrw/nd2reader

@WaterKnight1998
Copy link
Author

Hi,

Sorry, the open only works with actual file paths. As this project is merely wrapping the ND2 reading library from Nikon, we don’t have much control.

You could try virtual file systems if you want to stay in memory, but it depends on your OS how that works. I don’t have experience with that.

Or, try a pure Python alternative like https://github.com/rbnvrw/nd2reader

Thank you! What is the approach with virtual file system?

@WaterKnight1998
Copy link
Author

WaterKnight1998 commented Jun 6, 2020

@caspervdw I have created a temporal file in /dev/shm from which nd2reader read contents. However, after clossing reader, and deleting temporal file. It is still there. So I think your library closes bad the file. Do you maintain any reference inside it?

@lurch
Copy link

lurch commented Jun 6, 2020

@caspervdw There's more context in PyFilesystem/pyfilesystem2#402 (comment)

@WaterKnight1998
Copy link
Author

@caspervdw There's more context in PyFilesystem/pyfilesystem2#402 (comment)

Right!

@caspervdw
Copy link
Member

Hi,
I do think this library properly closes the reader. The correct ND2SDK function is called at reader.close(). Even if you do not call reader.close(), it should still be done when the reader goes out of scope. It happens at

def close(self):

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

3 participants