MemoryObjectStorage class

An ObjectStorage holding every object in the heap.

The default for tests and for an embedded, ephemeral registry. It implements the contract exactly — ranges, checksum verification, key safety — so a test that passes against it is testing the same semantics the S3 and GCS backends provide, not a simplified stand-in.

It cannot issue presigned URLs; callers stream bytes through instead.

It is bounded by memory. maxTotalBytes caps what it will hold and throws StorageException past it, rather than growing until the process is killed. Pass null to disable the cap when a test knows what it is doing.

Implemented types

Constructors

MemoryObjectStorage({String id = 'memory', int? maxTotalBytes = 256 * 1024 * 1024})
Creates an empty in-memory store holding at most maxTotalBytes (default 256 MiB).

Properties

hashCode int
The hash code for this object.
no setterinherited
id String
A short identifier for this backend, used in logs and provider descriptors (local, s3:my-bucket, gcs:my-bucket).
final
keys Iterable<String>
The keys held, in insertion order.
no setter
length int
The number of objects held.
no setter
maxTotalBytes int?
The maximum total bytes retained, or null for unbounded.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportsPresignedUrls bool
Whether this backend can issue presigned download URLs, so the caller can decide between redirecting a client and proxying the bytes without first asking for a URL and handling null.
no setteroverride

Methods

close() Future<void>
Releases any resources (HTTP clients, file handles).
override
delete(String key) Future<void>
Deletes key. Succeeds whether or not it existed.
override
exists(String key) Future<bool>
Whether key exists.
override
get(String key, {ByteRange? range}) Future<ObjectReader>
Opens key for reading, optionally restricted to range.
override
Metadata for key, or null if it does not exist.
override
list({String? prefix, int? limit}) Future<List<String>>
Keys under prefix, at most limit of them, in lexicographic order.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
presignedUrl(String key, {Duration expiresIn = const Duration(minutes: 15), String? filename, String? contentType}) Future<Uri?>
A time-limited URL a client can fetch key from directly, or null if this backend cannot issue one.
override
put(String key, Stream<List<int>> data, {int? length, String contentType = 'application/octet-stream', String? expectedSha256, Map<String, String> metadata = const {}}) Future<StoredObject>
Streams data into key, replacing anything already there.
override
toString() String
A string representation of this object.
inherited
usedBytes() Future<int?>
Total bytes stored, or null if the backend cannot compute it cheaply.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited