\Drupal\strata\File FileMapDiff

What changed between two versions of a file, block by block.

The thing that decides what a new version costs. A version whose blocks are already in the store costs a map and nothing else; one with thirty-three new blocks costs those blocks.

Two counts, and they answer different questions. The blocks at changed POSITIONS say how much of the file looks different, which is what tells a shift from an edit. The blocks that are genuinely NEW say what has to be uploaded, and it is always the smaller number - a shifted file is full of blocks that moved rather than changed, and a moved block is already stored.

Summary

Methods
Properties
Constants
__construct
between
isUnchanged
isFirstCapture
changedRatio
uploadCeiling
uploadShare
summary
jsonSerialize
before
after
changedPositions
newBlocks
droppedBlocks
No public constants found
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Properties

$before

$before : ?\Drupal\strata\File\FileMap

Type

FileMap|null

$after

$after : \Drupal\strata\File\FileMap

Type

FileMap

$changedPositions

$changedPositions : array

Type

array<string|int, mixed>

$newBlocks

$newBlocks : array

Type

array<string|int, mixed>

$droppedBlocks

$droppedBlocks : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(\Drupal\strata\File\FileMap|null  $before, \Drupal\strata\File\FileMap  $after, list  $changedPositions, list  $newBlocks, list  $droppedBlocks) : mixed

Constructs a diff.

Parameters

\Drupal\strata\File\FileMap|null $before

The previous version, or NULL for a first capture.

\Drupal\strata\File\FileMap $after

The version being stored.

list $changedPositions

Block indexes whose content differs from the same index in the previous version, plus every index past the end of it.

list $newBlocks

Block addresses the previous version did not contain anywhere, in first-seen order.

list $droppedBlocks

Block addresses the previous version contained and this one does not.

Returns

mixed —

between()

between(\Drupal\strata\File\FileMap|null  $before, \Drupal\strata\File\FileMap  $after) : \Drupal\strata\File\FileMapDiff

Compares two versions of a file.

Parameters

\Drupal\strata\File\FileMap|null $before

The previous version, or NULL for a first capture, which reports every block as new.

\Drupal\strata\File\FileMap $after

The version being stored.

Throws

\RuntimeException

When the two maps were split at different block sizes, which would make every position comparison meaningless. Recapturing the file at the new size is the answer, and saying so beats reporting a 100% change as though the file had been rewritten.

Returns

\Drupal\strata\File\FileMapDiff —

The diff.

isUnchanged()

isUnchanged() : bool

Whether anything changed at all.

Returns

bool —

TRUE when the two versions are identical.

isFirstCapture()

isFirstCapture() : bool

Whether this is a first capture.

Returns

bool —

TRUE when there was no previous version.

changedRatio()

changedRatio() : float

Share of the file's positions whose content differs.

The number a shift is detected from. Measured on a 256 MiB file: a 2 MiB in-place edit moves 0.81% of it, and a 2 MiB insertion moves 60.79%.

Returns

float —

A fraction between 0 and 1. A first capture is 1.0, since none of it was there before.

uploadCeiling()

uploadCeiling() : int

Bytes that have to be uploaded, at most.

Returns

int —

Bytes. An upper bound, because the file's last block is usually short.

uploadShare()

uploadShare() : float

What share of the file has to be uploaded.

Returns

float —

A fraction of the file's length, which is what "a 2 MiB edit costs 0.81%" is measuring.

summary()

summary() : string

One line describing the change.

Returns

string —

The summary.

jsonSerialize()

jsonSerialize() : array<string,mixed>

{@inheritdoc}

Returns

array

The diff as data. The block lists are counted rather than listed, because a diff of a large file holds thousands of digests and a report does not need them.