Mercurial > hg > orthanc
comparison OrthancServer/Resources/Samples/Tools/RecoverCompressedFile.cpp @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | Resources/Samples/Tools/RecoverCompressedFile.cpp@94f4a18a79cc |
children | 05b8fd21089c |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "../../../Core/Compression/ZlibCompressor.h" | |
23 #include "../../../Core/SystemToolbox.h" | |
24 #include "../../../Core/OrthancException.h" | |
25 | |
26 #include <stdio.h> | |
27 | |
28 int main(int argc, const char* argv[]) | |
29 { | |
30 if (argc != 2 && argc != 3) | |
31 { | |
32 fprintf(stderr, "Maintenance tool to recover a DICOM file that was compressed by Orthanc.\n\n"); | |
33 fprintf(stderr, "Usage: %s <input> [output]\n", argv[0]); | |
34 fprintf(stderr, "If \"output\" is not given, the data will be output to stdout\n"); | |
35 return -1; | |
36 } | |
37 | |
38 try | |
39 { | |
40 fprintf(stderr, "Reading the file into memory...\n"); | |
41 fflush(stderr); | |
42 | |
43 std::string content; | |
44 Orthanc::SystemToolbox::ReadFile(content, argv[1]); | |
45 | |
46 fprintf(stderr, "Decompressing the content of the file...\n"); | |
47 fflush(stderr); | |
48 | |
49 Orthanc::ZlibCompressor compressor; | |
50 std::string uncompressed; | |
51 compressor.Uncompress(uncompressed, | |
52 content.empty() ? NULL : content.c_str(), | |
53 content.size()); | |
54 | |
55 fprintf(stderr, "Writing the uncompressed data...\n"); | |
56 fflush(stderr); | |
57 | |
58 if (argc == 3) | |
59 { | |
60 Orthanc::SystemToolbox::WriteFile(uncompressed, argv[2]); | |
61 } | |
62 else | |
63 { | |
64 if (uncompressed.size() > 0) | |
65 { | |
66 fwrite(&uncompressed[0], uncompressed.size(), 1, stdout); | |
67 } | |
68 } | |
69 | |
70 fprintf(stderr, "Done!\n"); | |
71 } | |
72 catch (Orthanc::OrthancException& e) | |
73 { | |
74 fprintf(stderr, "Error: %s\n", e.What()); | |
75 return -1; | |
76 } | |
77 | |
78 return 0; | |
79 } |