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

Read/write nrrd from/to memory #108

Closed
arnegroskurth opened this issue Mar 10, 2020 · 4 comments
Closed

Read/write nrrd from/to memory #108

arnegroskurth opened this issue Mar 10, 2020 · 4 comments

Comments

@arnegroskurth
Copy link

The library seems to be missing an interface to simply parse a nrrd-record from another source then an actual file on disk.

Would e.g. an interface based on a provided instance of _IOBase make sense for you?

@addisonElliott
Copy link
Collaborator

Hello,

The nrrd.read_header and nrrd.read_data functions accept file handles that I think should work for any IOBase class. Have you tested that yet to see if it fails?

The read_header function accepts any string iterable and just calls next() on it to get another line. The read_data calls close, seek, readline, read, all of which are present in IOBase.

If these functions are not able to accept any generic IOBase class, then I agree they should be generalized to do so if possible.

The nrrd.read() function calls the other two functions after opening the file locally. I'd be okay with adapting nrrd.read() to accept a file handle/stream instead of a filename. One thing to keep in mind is that the filename is used to determine the detached header or data filename, so this functionality will be broken.

@arnegroskurth
Copy link
Author

Reading actually works by passing in an instance of io.BytesIO.

But what about writing an nrrd record to memoy?

bernardopericacho added a commit to bernardopericacho/pynrrd that referenced this issue Jun 11, 2022
addisonElliott pushed a commit that referenced this issue Jun 17, 2022
## Changes

- `write` now supports as a parameter either a filename or a `io.BytesIO` object.
- refactor write method into:
   - `_write_default_header_entries` to write the default header entries generated by this package
   - `_handle_header_fields` to determine the headers based on the specified headers, data and index order
   - `_write_header` that used the logic from `_write_default_header_entries` and `_handle_header_fields` to write the headers
   - `write` used the methods above to encapsulate and reuse better the code
   - added new tests to check the functionality. Coverage still 100% after these changes
@moshecSeetrue
Copy link

Hi,
Does anyone know when a new version with this commit should be out?

@addisonElliott
Copy link
Collaborator

I can’t give a timeline, but we’re waiting to add some other improvements to the library and then a v1.0.0 release is happening (with breaking changes).

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