@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support a file data iteration interface for large files

Summary: Ref T7149. A couple diffs down the line, this will let us emit chunked files without doing all the work up front or holding the entire file in RAM.

Test Plan:
(Some newlines added for clarity.)

```
$ ./bin/files cat F942
ABCDEFGHIJKLMNOPQRSTUVWXYZ
$ ./bin/files cat F942 --begin 1
BCDEFGHIJKLMNOPQRSTUVWXYZ
$ ./bin/files cat F942 --end 10
ABCDEFGHIJ
$ ./bin/files cat F942 --begin 3 --end 5
DE
$
```

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: joshuaspence, epriestley

Maniphest Tasks: T7149

Differential Revision: https://secure.phabricator.com/D12071

+42 -1
+17 -1
src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
··· 11 11 ->setArguments( 12 12 array( 13 13 array( 14 + 'name' => 'begin', 15 + 'param' => 'bytes', 16 + 'help' => pht('Begin printing at a specific offset.'), 17 + ), 18 + array( 19 + 'name' => 'end', 20 + 'param' => 'bytes', 21 + 'help' => pht('End printing at a specific offset.'), 22 + ), 23 + array( 14 24 'name' => 'names', 15 25 'wildcard' => true, 16 26 ), ··· 31 41 32 42 $file = head($this->loadFilesWithNames($names)); 33 43 34 - echo $file->loadFileData(); 44 + $begin = $args->getArg('begin'); 45 + $end = $args->getArg('end'); 46 + 47 + $iterator = $file->getFileDataIterator($begin, $end); 48 + foreach ($iterator as $data) { 49 + echo $data; 50 + } 35 51 36 52 return 0; 37 53 }
+25
src/applications/files/storage/PhabricatorFile.php
··· 603 603 return $data; 604 604 } 605 605 606 + 607 + /** 608 + * Return an iterable which emits file content bytes. 609 + * 610 + * @param int Offset for the start of data. 611 + * @param int Offset for the end of data. 612 + * @return Iterable Iterable object which emits requested data. 613 + */ 614 + public function getFileDataIterator($begin = null, $end = null) { 615 + // The default implementation is trivial and just loads the entire file 616 + // upfront. 617 + $data = $this->loadFileData(); 618 + 619 + if ($begin !== null && $end !== null) { 620 + $data = substr($data, $begin, ($end - $begin)); 621 + } else if ($begin !== null) { 622 + $data = substr($data, $begin); 623 + } else if ($end !== null) { 624 + $data = substr($data, 0, $end); 625 + } 626 + 627 + return array($data); 628 + } 629 + 630 + 606 631 public function getViewURI() { 607 632 if (!$this->getPHID()) { 608 633 throw new Exception(