Skip to content

Define reader usable by Xarray#1

Merged
maxrjones merged 2 commits intomainfrom
add-reader
Nov 21, 2025
Merged

Define reader usable by Xarray#1
maxrjones merged 2 commits intomainfrom
add-reader

Conversation

@maxrjones
Copy link
Member

cc @hrodmn

Copy link

Choose a reason for hiding this comment

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

Thanks for sharing this! After our discussion this morning I experimented with a reader that caches the file to a MemoryStore then handles the read/seek operations on the file in memory:

class ObstoreMemCacheReader(ObstoreReader):
    _reader: ReadableFile
    _memstore: MemoryStore

    def __init__(self, store: ObjectStore, path: str) -> None:
        """
        Create an obstore file reader that caches the specified path
        in a MemoryStore then performs reads from the file in memory.
        ----------
        store
            [ObjectStore][obstore.store.ObjectStore] for reading the file.
        path
            The path to the file within the store. This should not include the prefix.
        """
        self._memstore = MemoryStore()
        buffer = store.get(path).bytes()
        self._memstore.put(path, buffer)
        
        self._reader = obs.open_reader(self._memstore, path)

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

Successfully merging this pull request may close these issues.

2 participants