This repository was archived by the owner on Sep 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
core/controllers/components
modules/api/controllers/components Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -24,8 +24,9 @@ function __construct()
24
24
/**
25
25
* Calling this will stream the file to the client.
26
26
* The parameter is a bitstream dao.
27
+ * Optional second parameter is the download offset in bytes.
27
28
*/
28
- function download ($ bitstream )
29
+ function download ($ bitstream, $ offset = 0 )
29
30
{
30
31
$ mimetype = $ bitstream ->getMimetype ();
31
32
$ path = $ bitstream ->getAssetstore ()->getPath ().'/ ' .$ bitstream ->getPath ();
@@ -123,16 +124,20 @@ function download($bitstream)
123
124
ob_end_clean ();
124
125
}
125
126
127
+ if (is_numeric ($ offset ) && $ offset > 0 && $ offset <= $ fileSize )
128
+ {
129
+ fseek ($ handle , $ offset );
130
+ }
131
+
126
132
while (!feof ($ handle ) && connection_status () == 0 )
127
133
{
128
- $ buffer = fread ($ handle , $ chunkSize );
129
- echo $ buffer ;
134
+ echo fread ($ handle , $ chunkSize );
130
135
}
131
136
fclose ($ handle );
132
137
133
138
if (!$ this ->testingmode ) //don't exit if we are in testing mode
134
139
{
135
- exit (connection_status () == 0 && ! connection_aborted () );
140
+ exit ();
136
141
}
137
142
}
138
143
} //end class
Original file line number Diff line number Diff line change @@ -1171,6 +1171,7 @@ function bitstreamGet($args)
1171
1171
* @param id (Optional) The id of the bitstream
1172
1172
* @param checksum (Optional) The checksum of the bitstream
1173
1173
* @param name (Optional) Alternate filename to download as
1174
+ * @param offset (Optional) The download offset in bytes (used for resume)
1174
1175
*/
1175
1176
function bitstreamDownload ($ args )
1176
1177
{
@@ -1217,8 +1218,10 @@ function bitstreamDownload($args)
1217
1218
$ this ->_redirect ($ bitstream ->getPath ());
1218
1219
return ;
1219
1220
}
1221
+ $ offset = array_key_exists ('offset ' , $ args ) ? $ args ['offset ' ] : 0 ;
1222
+
1220
1223
$ componentLoader = new MIDAS_ComponentLoader ();
1221
1224
$ downloadComponent = $ componentLoader ->loadComponent ('DownloadBitstream ' );
1222
- $ downloadComponent ->download ($ bitstream );
1225
+ $ downloadComponent ->download ($ bitstream, $ offset );
1223
1226
}
1224
1227
} // end class
You can’t perform that action at this time.
0 commit comments