OLD | NEW |
1 /* Copyright 2014 Google Inc. All Rights Reserved. | 1 /* Copyright 2014 Google Inc. All Rights Reserved. |
2 | 2 |
3 Distributed under MIT license. | 3 Distributed under MIT license. |
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT | 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 */ | 5 */ |
6 | 6 |
7 /* Example main() function for Brotli library. */ | 7 /* Example main() function for Brotli library. */ |
8 | 8 |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 const clock_t clock_start = clock(); | 280 const clock_t clock_start = clock(); |
281 for (int i = 0; i < repeat; ++i) { | 281 for (int i = 0; i < repeat; ++i) { |
282 FILE* fin = OpenInputFile(input_path); | 282 FILE* fin = OpenInputFile(input_path); |
283 FILE* fout = OpenOutputFile(output_path, force); | 283 FILE* fout = OpenOutputFile(output_path, force); |
284 if (decompress) { | 284 if (decompress) { |
285 Decompresss(fin, fout); | 285 Decompresss(fin, fout); |
286 } else { | 286 } else { |
287 brotli::BrotliParams params; | 287 brotli::BrotliParams params; |
288 params.lgwin = lgwin; | 288 params.lgwin = lgwin; |
289 params.quality = quality; | 289 params.quality = quality; |
290 brotli::BrotliFileIn in(fin, 1 << 16); | 290 try { |
291 brotli::BrotliFileOut out(fout); | 291 brotli::BrotliFileIn in(fin, 1 << 16); |
292 if (!BrotliCompress(params, &in, &out)) { | 292 brotli::BrotliFileOut out(fout); |
293 fprintf(stderr, "compression failed\n"); | 293 if (!BrotliCompress(params, &in, &out)) { |
| 294 fprintf(stderr, "compression failed\n"); |
| 295 unlink(output_path); |
| 296 exit(1); |
| 297 } |
| 298 } catch (std::bad_alloc&) { |
| 299 fprintf(stderr, "not enough memory\n"); |
294 unlink(output_path); | 300 unlink(output_path); |
295 exit(1); | 301 exit(1); |
296 } | 302 } |
297 } | 303 } |
298 if (fclose(fin) != 0) { | 304 if (fclose(fin) != 0) { |
299 perror("fclose"); | 305 perror("fclose"); |
300 exit(1); | 306 exit(1); |
301 } | 307 } |
302 if (fclose(fout) != 0) { | 308 if (fclose(fout) != 0) { |
303 perror("fclose"); | 309 perror("fclose"); |
(...skipping 16 matching lines...) Expand all Loading... |
320 static_cast<double>(repeat * uncompressed_size) / (1024.0 * 1024.0); | 326 static_cast<double>(repeat * uncompressed_size) / (1024.0 * 1024.0); |
321 if (decompress) { | 327 if (decompress) { |
322 printf("Brotli decompression speed: "); | 328 printf("Brotli decompression speed: "); |
323 } else { | 329 } else { |
324 printf("Brotli compression speed: "); | 330 printf("Brotli compression speed: "); |
325 } | 331 } |
326 printf("%g MB/s\n", uncompressed_bytes_in_MB / duration); | 332 printf("%g MB/s\n", uncompressed_bytes_in_MB / duration); |
327 } | 333 } |
328 return 0; | 334 return 0; |
329 } | 335 } |
OLD | NEW |