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 try { | 290 brotli::BrotliFileIn in(fin, 1 << 16); |
291 brotli::BrotliFileIn in(fin, 1 << 16); | 291 brotli::BrotliFileOut out(fout); |
292 brotli::BrotliFileOut out(fout); | 292 if (!BrotliCompress(params, &in, &out)) { |
293 if (!BrotliCompress(params, &in, &out)) { | 293 fprintf(stderr, "compression failed\n"); |
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"); | |
300 unlink(output_path); | 294 unlink(output_path); |
301 exit(1); | 295 exit(1); |
302 } | 296 } |
303 } | 297 } |
304 if (fclose(fin) != 0) { | 298 if (fclose(fin) != 0) { |
305 perror("fclose"); | 299 perror("fclose"); |
306 exit(1); | 300 exit(1); |
307 } | 301 } |
308 if (fclose(fout) != 0) { | 302 if (fclose(fout) != 0) { |
309 perror("fclose"); | 303 perror("fclose"); |
(...skipping 16 matching lines...) Expand all Loading... |
326 static_cast<double>(repeat * uncompressed_size) / (1024.0 * 1024.0); | 320 static_cast<double>(repeat * uncompressed_size) / (1024.0 * 1024.0); |
327 if (decompress) { | 321 if (decompress) { |
328 printf("Brotli decompression speed: "); | 322 printf("Brotli decompression speed: "); |
329 } else { | 323 } else { |
330 printf("Brotli compression speed: "); | 324 printf("Brotli compression speed: "); |
331 } | 325 } |
332 printf("%g MB/s\n", uncompressed_bytes_in_MB / duration); | 326 printf("%g MB/s\n", uncompressed_bytes_in_MB / duration); |
333 } | 327 } |
334 return 0; | 328 return 0; |
335 } | 329 } |
OLD | NEW |