Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }