\Drupal\strata\Segment SegmentReader

Reads segment manifests back out of the store.

The codec a segment was written with is read from the object's own plaintext header rather than from the store's current settings, so changing a setting never makes an existing segment unreadable and nothing depends on provider metadata. The object key is the associated data the body was sealed with.

Summary

Methods
Properties
Constants
__construct
read
keys
all
keysBetween
secondOf
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
split
provider
codecs
cipher
No private constants found

Properties

$codecs

$codecs : \Drupal\strata\Codec\CodecRegistry

Type

CodecRegistry

$cipher

$cipher : \Drupal\strata\Crypto\CipherInterface

Type

CipherInterface

Methods

__construct()

__construct(\Drupal\strata\Storage\StorageProviderInterface  $provider, \Drupal\strata\Codec\CodecRegistry  $codecs, \Drupal\strata\Crypto\CipherInterface  $cipher) : mixed

Constructs a reader.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $provider

Where segments live.

\Drupal\strata\Codec\CodecRegistry $codecs

Used to find the codec a segment was written with.

\Drupal\strata\Crypto\CipherInterface $cipher

Opens the manifest.

Returns

mixed —

read()

read(string  $key) : \Drupal\strata\Segment\SegmentManifest

Reads one segment.

Parameters

string $key

The object key the segment was written to.

Throws

\RuntimeException

When the segment is absent, fails to open, does not match its recorded digest, or carries a format version this release cannot read.

Returns

\Drupal\strata\Segment\SegmentManifest —

The manifest.

keys()

keys(int  $level = 0) : \Generator<int,string>

Every segment key at a level, in capture order.

Parameters

int $level

Compaction level.

Throws

\RuntimeException

When the listing fails.

Returns

\Generator

Object keys, oldest first.

all()

all(int  $level = 0) : \Generator<string,\Drupal\strata\Segment\SegmentManifest>

Every segment at a level, in capture order.

Parameters

int $level

Compaction level.

Throws

\RuntimeException

When a segment cannot be read.

Returns

\Generator

Object key keyed to its manifest, oldest first.

keysBetween()

keysBetween(int  $fromSecond, int  $toSecond, int  $level = 0) : list<string>

Segment keys covering a time range at a level.

Filters on the key rather than by reading manifests, since the key carries the epoch second the segment starts at. A compaction pass over an hour therefore costs one listing.

Parameters

int $fromSecond

Unix second to start at, inclusive.

int $toSecond

Unix second to end at, inclusive.

int $level

Compaction level.

Throws

\RuntimeException

When the listing fails.

Returns

list

Object keys, oldest first.

secondOf()

secondOf(string  $key) : int|null

The epoch second encoded in a segment key.

Parameters

string $key

The object key.

Returns

int|null —

The second, or NULL when the key is not shaped like a segment key.

split()

split(string  $key, string  $stored) : array{0: string, 1: string, 2: string}

Splits a stored segment into its header fields and sealed body.

Parameters

string $key

The object key, for error messages.

string $stored

The stored bytes.

Throws

\RuntimeException

When the header is absent, truncated, or names a format this release cannot read.

Returns

array{0: string, 1: string, 2: string} —

The codec id, the plaintext digest and the sealed body.