|
1 | | -#@local meths, i, urls, pair, url, expected, res1, good1, n, file, res2, good2, contents, r, res3, good3, bad, server, baseurl, iometh, opt, oldpref |
| 1 | +#@local meths, i, urls, pair, url, expected, res1, good1, n, file, res2, good2, contents, r, res3, good3, bad, server, baseurl, iometh, opt, oldpref, resumers, name |
2 | 2 | ############################################################################ |
3 | 3 | ## |
4 | 4 | #W download.tst Utils Package Thomas Breuer |
@@ -164,6 +164,55 @@ true |
164 | 164 | gap> IsExistingFile( file ); |
165 | 165 | false |
166 | 166 |
|
| 167 | +## 'resume' continues a partial file rather than fetching it again. The |
| 168 | +## test server answers a Range request with the remainder in upper case, so |
| 169 | +## a resumed download is distinguishable from a restarted one. |
| 170 | +gap> resumers:= Filtered( meths, r -> r.name in [ "via curl", "via wget" ] );; |
| 171 | +gap> for r in resumers do |
| 172 | +> FileString( file, "abcde" );; |
| 173 | +> res1:= r.download( Concatenation( baseurl, "/resumable" ), |
| 174 | +> rec( target:= file, resume:= true ) ); |
| 175 | +> if res1.success <> true then |
| 176 | +> Print( "resume failed for ", r.name, ": ", res1.error, "\n" ); |
| 177 | +> elif StringFile( file ) <> "abcdeFGHIJKLMNOPQRST" then |
| 178 | +> Print( "did not resume for ", r.name, ": ", StringFile( file ), "\n" ); |
| 179 | +> fi; |
| 180 | +> RemoveFile( file ); |
| 181 | +> od; |
| 182 | + |
| 183 | +## Without 'resume' the target is replaced, not appended to. |
| 184 | +gap> FileString( file, "abcde" );; |
| 185 | +gap> res1:= Download( Concatenation( baseurl, "/resumable" ), |
| 186 | +> rec( target:= file ) );; |
| 187 | +gap> StringFile( file ); |
| 188 | +"abcdefghijklmnopqrst" |
| 189 | + |
| 190 | +## Methods that cannot resume decline, rather than discarding the partial |
| 191 | +## file that a method which can resume needs. |
| 192 | +gap> iometh.download( Concatenation( baseurl, "/resumable" ), |
| 193 | +> rec( target:= file, resume:= true ) ).error; |
| 194 | +"no support for resuming" |
| 195 | + |
| 196 | +## With 'resume', a failed download keeps the partial file to continue from. |
| 197 | +## Without this, the clean-up in 'Download' would throw away the very thing |
| 198 | +## the next attempt is meant to continue. |
| 199 | +gap> FileString( file, "abcde" );; |
| 200 | +gap> res1:= Download( Concatenation( baseurl, "/missing" ), |
| 201 | +> rec( target:= file, resume:= true ) );; |
| 202 | +gap> res1.success; |
| 203 | +false |
| 204 | +gap> StringFile( file ); |
| 205 | +"abcde" |
| 206 | +gap> RemoveFile( file );; |
| 207 | + |
| 208 | +## 'resume' is only declined when it is actually requested: a method must |
| 209 | +## not be skipped merely because the component is present. |
| 210 | +gap> res1:= Download( Concatenation( baseurl, "/file" ), |
| 211 | +> rec( target:= file, resume:= false ) );; |
| 212 | +gap> res1.success; |
| 213 | +true |
| 214 | +gap> RemoveFile( file );; |
| 215 | + |
167 | 216 | ## test errors and redirects |
168 | 217 | gap> res1:= Download( Concatenation( baseurl, "/missing" ) );; |
169 | 218 | gap> res1.success = false; |
|
0 commit comments