Class FileSystemArtifactStore
- Namespace
- OptunaSharp.Artifacts
- Assembly
- OptunaSharp.dll
An artifact store for file systems.
Port of optuna/artifacts/_filesystem.py: FileSystemArtifactStore.
public class FileSystemArtifactStore : IArtifactStore
- Inheritance
-
FileSystemArtifactStore
- Implements
- Inherited Members
Examples
var basePath = "./artifacts";
Directory.CreateDirectory(basePath);
var artifactStore = new FileSystemArtifactStore(basePath: basePath);
// inside an objective:
ArtifactFunctions.UploadArtifact(artifactStore, filePath, trial);
Constructors
FileSystemArtifactStore(string)
Uses an existing directory as the root for artifact files.
public FileSystemArtifactStore(string basePath)
Parameters
basePathstringThe base path to a directory to store artifacts.
Remarks
The constructor stores the path without creating or validating the directory.
Methods
OpenReader(string)
Opens binary artifact content for reading.
public Stream OpenReader(string artifactId)
Parameters
artifactIdstringIdentifier of the artifact within the configured store.
Returns
- Stream
A readable stream owned by the caller; dispose it after reading.
Exceptions
- ArtifactNotFound
The artifact does not exist.
- Exception
The configured store cannot retrieve the artifact.
- ValueError
The artifact identifier is rooted or escapes the configured directory.
- IOException
A filesystem operation fails.
- UnauthorizedAccessException
Filesystem access is denied.
Remove(string)
Deletes the artifact identified by its store key.
public void Remove(string artifactId)
Parameters
artifactIdstringIdentifier of the artifact within the configured store.
Exceptions
- ArtifactNotFound
The backend reports that the artifact is absent.
- Exception
The backend cannot delete the artifact.
- ValueError
The artifact identifier is rooted or escapes the configured directory.
- IOException
A filesystem operation fails.
- UnauthorizedAccessException
Filesystem access is denied.
Write(string, Stream)
Copies artifact content into the store without taking ownership of the input stream.
public void Write(string artifactId, Stream contentBody)
Parameters
artifactIdstringIdentifier of the artifact within the configured store.
contentBodyStreamReadable content stream; ownership stays with the caller.
Exceptions
- Exception
The backend or input stream fails during the upload.
- ValueError
The artifact identifier is rooted or escapes the configured directory.
- IOException
A filesystem operation fails.
- UnauthorizedAccessException
Filesystem access is denied.