Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 3023da9

Browse files
committed
ENH: refs #0319. Add offset parameter to download component
1 parent 22c0ab5 commit 3023da9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

core/controllers/components/DownloadBitstreamComponent.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function __construct()
2424
/**
2525
* Calling this will stream the file to the client.
2626
* The parameter is a bitstream dao.
27+
* Optional second parameter is the download offset in bytes.
2728
*/
28-
function download($bitstream)
29+
function download($bitstream, $offset = 0)
2930
{
3031
$mimetype = $bitstream->getMimetype();
3132
$path = $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath();
@@ -123,16 +124,20 @@ function download($bitstream)
123124
ob_end_clean();
124125
}
125126

127+
if(is_numeric($offset) && $offset > 0 && $offset <= $fileSize)
128+
{
129+
fseek($handle, $offset);
130+
}
131+
126132
while(!feof($handle) && connection_status() == 0)
127133
{
128-
$buffer = fread($handle, $chunkSize);
129-
echo $buffer;
134+
echo fread($handle, $chunkSize);
130135
}
131136
fclose($handle);
132137

133138
if(!$this->testingmode) //don't exit if we are in testing mode
134139
{
135-
exit(connection_status() == 0 && !connection_aborted());
140+
exit();
136141
}
137142
}
138143
} //end class

modules/api/controllers/components/ApiComponent.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ function bitstreamGet($args)
11711171
* @param id (Optional) The id of the bitstream
11721172
* @param checksum (Optional) The checksum of the bitstream
11731173
* @param name (Optional) Alternate filename to download as
1174+
* @param offset (Optional) The download offset in bytes (used for resume)
11741175
*/
11751176
function bitstreamDownload($args)
11761177
{
@@ -1217,8 +1218,10 @@ function bitstreamDownload($args)
12171218
$this->_redirect($bitstream->getPath());
12181219
return;
12191220
}
1221+
$offset = array_key_exists('offset', $args) ? $args['offset'] : 0;
1222+
12201223
$componentLoader = new MIDAS_ComponentLoader();
12211224
$downloadComponent = $componentLoader->loadComponent('DownloadBitstream');
1222-
$downloadComponent->download($bitstream);
1225+
$downloadComponent->download($bitstream, $offset);
12231226
}
12241227
} // end class

0 commit comments

Comments
 (0)