anystore.store.virtual
VirtualStore
Temporary file storage for local processing
Source code in anystore/store/virtual.py
get_virtual_path(uri, store=None, tmp_prefix=None, keep=False, **kwargs)
Download a file for temporary local processing and get its local path. If
the file itself is already on the local filesystem, the actual file will be
used. The file is cleaned up when leaving the context, unless keep=True
is
given (except if it was a local file, it won't be deleted in any case)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
Uri
|
Any uri fsspec can handle |
required |
store
|
BaseStore | None
|
An initialized store to fetch the uri from |
None
|
tmp_prefix
|
str | None
|
Set a manual temporary prefix, otherwise random |
None
|
keep
|
bool | None
|
Don't delete the file after leaving context, default |
False
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
Type | Description |
---|---|
Path
|
The absolute temporary |
Source code in anystore/store/virtual.py
open_virtual(uri, store=None, tmp_prefix=None, keep=False, checksum=DEFAULT_HASH_ALGORITHM, **kwargs)
Download a file for temporary local processing and get its checksum and an
open handler. If the file itself is already on the local filesystem, the
actual file will be used. The file is cleaned up when leaving the context,
unless keep=True
is given (except if it was a local file, it won't be
deleted in any case)
Example
with open_virtual("http://example.org/test.txt") as fh:
smart_write(uri=f"./local/{fh.checksum}", fh.read())
# without checksum computation:
with open_virtual("http://example.org/test.txt", checksum=None, keep=True) as fh:
print(fh.read())
# still exists after leaving context
assert fh.path.exists()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
Uri
|
Any uri fsspec can handle |
required |
store
|
BaseStore | None
|
An initialized store to fetch the uri from |
None
|
tmp_prefix
|
str | None
|
Set a manual temporary prefix, otherwise random |
None
|
keep
|
bool | None
|
Don't delete the file after leaving context, default |
False
|
checksum
|
str | None
|
Algorithm from |
DEFAULT_HASH_ALGORITHM
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
Type | Description |
---|---|
VirtualIO
|
A generic file-handler like context object. It has 3 extra attributes:
- |