Overview
Comment: | utils/ofhttp: Support for continuing downloads |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
336a6e129b3a367fe08bf4217b6132a9 |
User & Date: | js on 2015-04-26 14:57:19 |
Other Links: | manifest | tags |
Context
2015-04-26
| ||
16:06 | utils/ofhttp: Better error output and small bugfix check-in: 06b8800f20 user: js tags: trunk | |
14:57 | utils/ofhttp: Support for continuing downloads check-in: 336a6e129b user: js tags: trunk | |
14:08 | utils/ofhttp: Better error output check-in: 9fb003e423 user: js tags: trunk | |
Changes
Modified utils/ofhttp/OFHTTP.m from [0c3783e492] to [157aaf05ca].
︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | + + - + - + + | #import "OFAddressTranslationFailedException.h" #import "OFConnectionFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFStatItemFailedException.h" #import "OFUnsupportedProtocolException.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) @interface OFHTTP: OFObject { OFArray *_URLs; size_t _URLIndex; int _errorCode; OFString *_outputPath; bool _continue, _quiet; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; |
︙ | |||
95 96 97 98 99 100 101 | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | - + + + + | return self; } - (void)applicationDidFinishLaunching { OFOptionsParser *optionsParser = |
︙ | |||
209 210 211 212 213 214 215 216 217 218 219 220 221 | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | + - + | return false; } - (void)downloadNextURL { OFString *URLString = nil; OFURL *URL; OFMutableDictionary *clientHeaders; OFHTTPRequest *request; OFHTTPResponse *response; OFDictionary *headers; OFString *fileName, *lengthString, *type; _length = -1; |
︙ | |||
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + | _errorCode = 1; goto next; } if (!_quiet) [of_stdout writeFormat: @"⇣ %@", [URL string]]; if (_outputPath != nil) fileName = _outputPath; else fileName = [[URL path] lastPathComponent]; clientHeaders = [OFMutableDictionary dictionaryWithObject: @"OFHTTP" forKey: @"User-Agent"]; if (_continue) { @try { off_t size = [OFFile sizeOfFileAtPath: fileName]; OFString *range; if (size > INTMAX_MAX) @throw [OFOutOfRangeException exception]; _resumedFrom = (intmax_t)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; } @catch (OFStatItemFailedException *e) { } } request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; @try { response = [_HTTPClient performRequest: request]; } @catch (OFHTTPRequestFailedException *e) { if (!_quiet) [of_stdout writeFormat: @" ➜ %d\n", [[e response] statusCode]]; |
︙ | |||
318 319 320 321 322 323 324 | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | - - - - - - + + - + + - + + - + - + + + - + - + + + + | if (!_quiet) [of_stdout writeFormat: @" ➜ %d\n", [response statusCode]]; headers = [response headers]; lengthString = [headers objectForKey: @"Content-Length"]; type = [headers objectForKey: @"Content-Type"]; |
︙ |
Modified utils/ofhttp/ProgressBar.h from [e0dcfb0362] to [fea9147d40].
︙ | |||
17 18 19 20 21 22 23 | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | - + - + + | #import "OFObject.h" @class OFDate; @class OFTimer; @interface ProgressBar: OFObject { |
Modified utils/ofhttp/ProgressBar.m from [c13bb41aea] to [15aadddba2].
︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | + + | #define KIBIBYTE (1024) #define BAR_WIDTH 52 #define UPDATE_INTERVAL 0.1 @implementation ProgressBar - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _timer = [[OFTimer scheduledTimerWithTimeInterval: UPDATE_INTERVAL target: self selector: @selector(draw) repeats: true] retain]; |
︙ | |||
71 72 73 74 75 76 77 | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | - - + + + + | } - (void)_drawProgress { uint_fast8_t i; float bars, percent, bps; |
︙ | |||
127 128 129 130 131 132 133 | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | - - + + + - - + + + - - + + + - + + | } - (void)_drawReceived { float bps; if (_received >= GIBIBYTE) |
︙ |