comparison Resources/Samples/Tools/RecoverCompressedFile.cpp @ 680:571583642ce2

Tool to recover compressed files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 Jan 2014 16:20:05 +0100
parents
children 44382c8bcd15
comparison
equal deleted inserted replaced
678:3e4c2433f12b 680:571583642ce2
1 #include "../../../Core/Compression/ZlibCompressor.h"
2 #include "../../../Core/Toolbox.h"
3 #include "../../../Core/OrthancException.h"
4
5 #include <stdio.h>
6
7 int main(int argc, const char* argv[])
8 {
9 if (argc != 2 && argc != 3)
10 {
11 fprintf(stderr, "Maintenance tool to recover a DICOM file that was compressed by Orthanc.\n\n");
12 fprintf(stderr, "Usage: %s <input> [output]\n", argv[0]);
13 fprintf(stderr, "If \"output\" is not given, the data will be output to stdout\n");
14 return -1;
15 }
16
17 try
18 {
19 fprintf(stderr, "Reading the file into memory...\n");
20 fflush(stderr);
21
22 std::string content;
23 Orthanc::Toolbox::ReadFile(content, argv[1]);
24
25 fprintf(stderr, "Decompressing the content of the file...\n");
26 fflush(stderr);
27
28 Orthanc::ZlibCompressor compressor;
29 std::string uncompressed;
30 compressor.Uncompress(uncompressed, content);
31
32 fprintf(stderr, "Writing the uncompressed data...\n");
33 fflush(stderr);
34
35 if (argc == 3)
36 {
37 Orthanc::Toolbox::WriteFile(uncompressed, argv[2]);
38 }
39 else
40 {
41 if (uncompressed.size() > 0)
42 {
43 fwrite(&uncompressed[0], uncompressed.size(), 1, stdout);
44 }
45 }
46
47 fprintf(stderr, "Done!\n");
48 }
49 catch (Orthanc::OrthancException& e)
50 {
51 fprintf(stderr, "Error: %s\n", e.What());
52 return -1;
53 }
54
55 return 0;
56 }