protected function loadPage() { $table = new PhabricatorFileChunk(); $conn_r = $table->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); return $table->loadAllFromArray($data); }
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 static function newChunkedFile(PhabricatorFileStorageEngine $engine, $length, array $params) { $file = self::initializeNewFile(); $file->setByteSize($length); // TODO: We might be able to test the first chunk in order to figure // this out more reliably, since MIME detection usually examines headers. // However, enormous files are probably always either actually raw data // or reasonable to treat like raw data. $file->setMimeType('application/octet-stream'); $chunked_hash = idx($params, 'chunkedHash'); if ($chunked_hash) { $file->setContentHash($chunked_hash); } else { // See PhabricatorChunkedFileStorageEngine::getChunkedHash() for some // discussion of this. $seed = Filesystem::readRandomBytes(64); $hash = PhabricatorChunkedFileStorageEngine::getChunkedHashForInput($seed); $file->setContentHash($hash); } $file->setStorageEngine($engine->getEngineIdentifier()); $file->setStorageHandle(PhabricatorFileChunk::newChunkHandle()); $file->setStorageFormat(self::STORAGE_FORMAT_RAW); $file->setIsPartial(1); $file->readPropertiesFromParameters($params); return $file; }
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; }
public static function newChunkedFile(PhabricatorFileStorageEngine $engine, $length, array $params) { $file = self::initializeNewFile(); $file->setByteSize($length); // NOTE: Once we receive the first chunk, we'll detect its MIME type and // update the parent file. This matters for large media files like video. $file->setMimeType('application/octet-stream'); $chunked_hash = idx($params, 'chunkedHash'); if ($chunked_hash) { $file->setContentHash($chunked_hash); } else { // See PhabricatorChunkedFileStorageEngine::getChunkedHash() for some // discussion of this. $seed = Filesystem::readRandomBytes(64); $hash = PhabricatorChunkedFileStorageEngine::getChunkedHashForInput($seed); $file->setContentHash($hash); } $file->setStorageEngine($engine->getEngineIdentifier()); $file->setStorageHandle(PhabricatorFileChunk::newChunkHandle()); // Chunked files are always stored raw because they do not actually store // data. The chunks do, and can be individually formatted. $file->setStorageFormat(PhabricatorFileRawStorageFormat::FORMATKEY); $file->setIsPartial(1); $file->readPropertiesFromParameters($params); return $file; }