| @@ 286-299 (lines=14) @@ | ||
| 283 | $this->createIndex(['filename' => 1, 'uploadDate' => 1]); |
|
| 284 | } |
|
| 285 | ||
| 286 | private function insertChunksFromFile($file, $fileInfo) |
|
| 287 | { |
|
| 288 | $length = $fileInfo['length']; |
|
| 289 | $chunkSize = $fileInfo['chunkSize']; |
|
| 290 | $fileId = $fileInfo['_id']; |
|
| 291 | $offset = 0; |
|
| 292 | $i = 0; |
|
| 293 | ||
| 294 | while ($offset < $length) { |
|
| 295 | $data = fread($file, $chunkSize); |
|
| 296 | $this->insertChunk($fileId, $data, $i++); |
|
| 297 | $offset += $chunkSize; |
|
| 298 | } |
|
| 299 | } |
|
| 300 | ||
| 301 | private function calculateMD5($file, $length) |
|
| 302 | { |
|
| @@ 309-322 (lines=14) @@ | ||
| 306 | return md5($data); |
|
| 307 | } |
|
| 308 | ||
| 309 | private function insertChunksFromBytes($bytes, $fileInfo) |
|
| 310 | { |
|
| 311 | $length = $fileInfo['length']; |
|
| 312 | $chunkSize = $fileInfo['chunkSize']; |
|
| 313 | $fileId = $fileInfo['_id']; |
|
| 314 | $offset = 0; |
|
| 315 | $i = 0; |
|
| 316 | ||
| 317 | while ($offset < $length) { |
|
| 318 | $data = mb_substr($bytes, $offset, $chunkSize, '8bit'); |
|
| 319 | $this->insertChunk($fileId, $data, $i++); |
|
| 320 | $offset += $chunkSize; |
|
| 321 | } |
|
| 322 | } |
|
| 323 | ||
| 324 | private function insertChunk($id, $data, $chunkNumber) |
|
| 325 | { |
|