Page MenuHomePhabricator

D12071.diff
No OneTemporary

D12071.diff

diff --git a/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
--- a/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
+++ b/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
@@ -11,6 +11,16 @@
->setArguments(
array(
array(
+ 'name' => 'begin',
+ 'param' => 'bytes',
+ 'help' => pht('Begin printing at a specific offset.'),
+ ),
+ array(
+ 'name' => 'end',
+ 'param' => 'bytes',
+ 'help' => pht('End printing at a specific offset.'),
+ ),
+ array(
'name' => 'names',
'wildcard' => true,
),
@@ -31,7 +41,13 @@
$file = head($this->loadFilesWithNames($names));
- echo $file->loadFileData();
+ $begin = $args->getArg('begin');
+ $end = $args->getArg('end');
+
+ $iterator = $file->getFileDataIterator($begin, $end);
+ foreach ($iterator as $data) {
+ echo $data;
+ }
return 0;
}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -603,6 +603,31 @@
return $data;
}
+
+ /**
+ * Return an iterable which emits file content bytes.
+ *
+ * @param int Offset for the start of data.
+ * @param int Offset for the end of data.
+ * @return Iterable Iterable object which emits requested data.
+ */
+ public function getFileDataIterator($begin = null, $end = null) {
+ // The default implementation is trivial and just loads the entire file
+ // upfront.
+ $data = $this->loadFileData();
+
+ if ($begin !== null && $end !== null) {
+ $data = substr($data, $begin, ($end - $begin));
+ } else if ($begin !== null) {
+ $data = substr($data, $begin);
+ } else if ($end !== null) {
+ $data = substr($data, 0, $end);
+ }
+
+ return array($data);
+ }
+
+
public function getViewURI() {
if (!$this->getPHID()) {
throw new Exception(

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 30, 5:07 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6712949
Default Alt Text
D12071.diff (2 KB)

Event Timeline