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

Be able to gain access to the "File" API through "Dir" API #16

Closed
manoss96 opened this issue Mar 16, 2023 · 0 comments · Fixed by #18
Closed

Be able to gain access to the "File" API through "Dir" API #16

manoss96 opened this issue Mar 16, 2023 · 0 comments · Fixed by #18
Assignees
Labels
enhancement New feature or request

Comments

@manoss96
Copy link
Owner

manoss96 commented Mar 16, 2023

All classes within the Dir API should be able to provide instant access to a file through the File API, for example:

from fluke.storage import LocalDir

# Reference a directory through the "Dir" API.
dir = LocalDir(dir='path/to/dir')

# Gain access to the "File" API through a "Dir" method, e.g. ``get_file``.
file = dir.get_file(path='path/to/file')

# Interact with a file through the "File" API.
size = file.get_size()

In the case of remote directories/files, all File instances generated by such method should have the following properties:

1. All files should share the same connection with the directory that generated them.

It should not be required for the user to explicitly close each generated file instance. Closing the directory should be enough. For example:

from fluke.storage import RemoteDir

# Reference remote directory.
dir = RemoteDir(auth=auth, path='/path/to/remote/dir/')

# Reference remote file.
file = dir.get_file(path='file.txt')

# Close connection.
dir.close()

# This should throw an error since connection has been closed.
size = file.get_size()

Similarly when using a context manager:

from fluke.storage import RemoteDir

auth = RemoteAuth.from_password(**credentials)

with RemoteDir(auth=auth, path='/path/to/remote/dir/') as dir:
   file = dir.get_file(path='file.txt')

# This should throw an error since connection has been closed.
size = file.get_size()

2. A "File" instance and the "Dir" instance that generated it should have access to the same metadata.

from fluke.storage import RemoteDir

# Reference remote directory.
dir = RemoteDir(auth=auth, path='/path/to/remote/dir/')

# Reference remote files.
file = dir.get_file(path='file.txt')

# Set metadata through "file"
file.set_metadata({'name': 'file.txt'})

# Access metadata through "dir".
metadata = dir.get_metadata('file.txt') # equals {'name': 'file.txt'}

3. A "File" instance and the "Dir" instance that generated it should have access to the same cache.

from fluke.storage import RemoteDir

# Reference directory and enable caching.
with RemoteDir(auth=auth, path='/path/to/remote/dir/', cache=True) as dir:
   # Get size of directory.
   dir_size = dir.get_size()
   # Reference a file.
   file = dir.get_file(path='file.txt')
   # File size should be fetched from the cache.
   file_size = file.get_size()
@manoss96 manoss96 self-assigned this Mar 16, 2023
@manoss96 manoss96 added the enhancement New feature or request label Mar 16, 2023
@manoss96 manoss96 linked a pull request Mar 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant