*/ private array $blobs = []; private int $bytes = 0; /** @param \Closure(string): string $store stores one blob, returns its id */ public function __construct( private \Closure $store, private int $blobSize = Repository::BLOB_SIZE, ) { } public function write(string $data): void { $this->buffer .= $data; $this->bytes += strlen($data); while (strlen($this->buffer) >= $this->blobSize) { $this->blobs[] = ($this->store)(substr($this->buffer, 0, $this->blobSize)); $this->buffer = substr($this->buffer, $this->blobSize); } } /** @return list blob ids, in order */ public function finish(): array { if ($this->buffer !== '') { $this->blobs[] = ($this->store)($this->buffer); $this->buffer = ''; } return $this->blobs; } public function bytes(): int { return $this->bytes; } }