private function writeChunk(PhabricatorFile $file, PhabricatorFileStorageEngine $engine) { $offset = $this->getTotalBytesWritten(); $max_length = $engine->getChunkSize(); $rope = $this->getRope(); $data = $rope->getPrefixBytes($max_length); $actual_length = strlen($data); $rope->removeBytesFromHead($actual_length); $chunk_data = PhabricatorFile::newFromFileData($data, array('name' => $file->getMonogram() . '.chunk-' . $offset, 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE)); $chunk = PhabricatorFileChunk::initializeNewChunk($file->getStorageHandle(), $offset, $offset + $actual_length); $chunk->setDataFilePHID($chunk_data->getPHID())->save(); $this->setTotalBytesWritten($offset + $actual_length); return $chunk; }
public function allocateChunks($length, array $properties) { $file = PhabricatorFile::newChunkedFile($this, $length, $properties); $chunk_size = $this->getChunkSize(); $handle = $file->getStorageHandle(); $chunks = array(); for ($ii = 0; $ii < $length; $ii += $chunk_size) { $chunks[] = PhabricatorFileChunk::initializeNewChunk($handle, $ii, min($ii + $chunk_size, $length)); } $file->openTransaction(); foreach ($chunks as $chunk) { $chunk->save(); } $file->save(); $file->saveTransaction(); return $file; }