IAsyncStorageScope#
- class ansys.bdm.api.iasync_storage_scope.IAsyncStorageScope#
Bases:
IAsyncReadStorageScope,ProtocolRepresents access to a Blob Data Management system. Allows consumers to produce and consume
EntityHandleinstances.This is the asynchronous version of the
IStorageScopeinterface.On dispose, files within the
storage_root()that have not been passed tostore()will be deleted.
Overview#
Create an |
|
Fully reads a passed in stream and returns a handle for the given content. |
|
Create an |
|
A local filesystem directory that can be used to stage files. |
|
The set of |
|
Delete the entities referenced by the handle. |
|
Return an object with a synchronous interface to the same scope. |
|
Create a recursive nested dictionary of EntityHandles from a directory. |
Track the set of files that are stored centrally. |
Import detail#
from ansys.bdm.api.iasync_storage_scope import IAsyncStorageScope
Method detail#
- async IAsyncStorageScope.__aenter__() IAsyncStorageScope#
Track the set of files that are stored centrally.
- async IAsyncStorageScope.store(from_: PathLike[str], mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.entity_handle.EntityHandle#
Create an
EntityHandlefrom a file on disk.Many blob handler implementations will try to optimize performance and the file contents may not be immediately read from disk. To avoid class 3 type errors, the file MUST NOT be externally modified after calling this method.
- Parameters:
- from_: PathLike[str]
The local file on disk which contains the contents for the generated
EntityHandle- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- An
EntityHandlethat rerpesents the contents of the read file at the moment - this method is invoked
- An
- async IAsyncStorageScope.store_stream(from_: anyio.abc.ByteReceiveStream | bytes, relative_location: pathlib.Path | None = None, mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.entity_handle.EntityHandle#
Fully reads a passed in stream and returns a handle for the given content.
- Parameters:
- from_Union[ByteReceiveStream, bytes]
The stream or in-memory bytes from which the new entity will be created
- relative_locationOptional[Path]
The nominal relative path of the entity. The path is relative to the storage_root of the scope. No data is expected at this location. The filename from this path will be used as the original name of the entity. If this parameter is not set then the implementation will generate a unique location.
- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- EntityHandle
The
EntityHandlethat represents the passed in data.
- async IAsyncStorageScope.begin_store(relative_location: pathlib.Path | None = None, mime_type: str | None = None, encoding: str | None = None) ansys.bdm.api.iasync_entity_writer.IAsyncEntityWriter#
Create an
EntityWriterby writing to a stream object.- Parameters:
- relative_locationOptional[Path]
The nominal relative path of the entity. The path is relative to the storage_root of the scope. No data is expected at this location. The filename from this path will be used as the original name of the entity. If this parameter is not set then the implementation will generate a unique location.
- mime_type: Optional[str]
Mime type of this file, if known. If None is passed in, the IAsyncStorageScope SHOULD use file extension to determine the mime type.
- encoding: Optional[str]
The Internet Assigned Numbers Authority (IANA) registered encoding name used for textual data. This MAY be None if not known and SHOULD NOT be set for binary mime types.
- Returns:
- IAsyncEntityWriter
An object which allows you to write to a stream and retrieve the handle.
- async IAsyncStorageScope.get_storage_root() pathlib.Path#
A local filesystem directory that can be used to stage files.
Since this folder is managed by the BDM implementation, there may be performance benefits to storing files here.
This directory usually is lazy instantiated on the first call to this function.
- async IAsyncStorageScope.get_stored_entities() collections.abc.AsyncIterator[ansys.bdm.api.entity_handle.EntityHandle]#
The set of
EntityHandleinstances that have been stored via this scope.
- async IAsyncStorageScope.destroy(*entities: ansys.bdm.api.entity_handle.EntityHandle) None#
Delete the entities referenced by the handle.
As
EntityHandleinstances are intended to be simple immutable structures that can be passed across process and service boundaries, their lifespan must be managed by an external system. This call allows the resources associated with a BlobHandle to be removed.- Parameters:
- *entities: EntityHandle
The entities to delete
- async IAsyncStorageScope.get_synchronous() ansys.bdm.api.istorage_scope.IStorageScope#
Return an object with a synchronous interface to the same scope.
- async IAsyncStorageScope.store_to_dictionary(root: PathLike[str], glob: str | None = None) ansys.bdm.api.recursive_dictionary.RecursiveDictionaryOfEntityHandles#
Create a recursive nested dictionary of EntityHandles from a directory.
This method creates a recursive nested dictionary containing EntityHandle objects for files and nested dictionaries for directories. If glob is None, all files at or within root are included in the result.
- Parameters:
- rootPathLike[str]
The root directory to store to a nested dictionary.
- globstr | None, optional
A glob pattern to filter which files and directories to include in the result. Behaves identically to Path.rglob() and is interpreted as relative to root. Default is None.
- Returns:
- RecursiveDictionaryOfEntityHandles
A recursive nested dictionary of EntityHandle objects.
- Raises:
- FileNotFoundError
If root does not exist.
- NotADirectoryError
If root is a file.
- NotFoundInLocalStorageRootError
If root is not within the storage root of storage scope.