Mercurial > hg > orthanc
comparison Core/Compression/ZlibCompressor.cpp @ 59:c996319e90bc orthanc-renaming
renaming in Core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:28:56 +0200 |
parents | a15e90e5d6fc |
children | 0ec5e2e327b1 |
comparison
equal
deleted
inserted
replaced
58:6da7fc87efaa | 59:c996319e90bc |
---|---|
1 /** | 1 /** |
2 * Palanthir - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 6 * This program is free software: you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
21 #include "ZlibCompressor.h" | 21 #include "ZlibCompressor.h" |
22 | 22 |
23 #include <stdio.h> | 23 #include <stdio.h> |
24 #include <string.h> | 24 #include <string.h> |
25 #include <zlib.h> | 25 #include <zlib.h> |
26 #include "../PalanthirException.h" | 26 #include "../OrthancException.h" |
27 | 27 |
28 namespace Palanthir | 28 namespace Orthanc |
29 { | 29 { |
30 void ZlibCompressor::SetCompressionLevel(uint8_t level) | 30 void ZlibCompressor::SetCompressionLevel(uint8_t level) |
31 { | 31 { |
32 if (level >= 10) | 32 if (level >= 10) |
33 { | 33 { |
34 throw PalanthirException("Zlib compression level must be between 0 (no compression) and 9 (highest compression"); | 34 throw OrthancException("Zlib compression level must be between 0 (no compression) and 9 (highest compression"); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 void ZlibCompressor::Compress(std::string& compressed, | 39 void ZlibCompressor::Compress(std::string& compressed, |
68 compressed.clear(); | 68 compressed.clear(); |
69 | 69 |
70 switch (error) | 70 switch (error) |
71 { | 71 { |
72 case Z_MEM_ERROR: | 72 case Z_MEM_ERROR: |
73 throw PalanthirException(ErrorCode_NotEnoughMemory); | 73 throw OrthancException(ErrorCode_NotEnoughMemory); |
74 | 74 |
75 default: | 75 default: |
76 throw PalanthirException(ErrorCode_InternalError); | 76 throw OrthancException(ErrorCode_InternalError); |
77 } | 77 } |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 | 81 |
89 return; | 89 return; |
90 } | 90 } |
91 | 91 |
92 if (compressedSize < sizeof(size_t)) | 92 if (compressedSize < sizeof(size_t)) |
93 { | 93 { |
94 throw PalanthirException("Zlib: The compressed buffer is ill-formed"); | 94 throw OrthancException("Zlib: The compressed buffer is ill-formed"); |
95 } | 95 } |
96 | 96 |
97 size_t uncompressedLength; | 97 size_t uncompressedLength; |
98 memcpy(&uncompressedLength, compressed, sizeof(size_t)); | 98 memcpy(&uncompressedLength, compressed, sizeof(size_t)); |
99 uncompressed.resize(uncompressedLength); | 99 uncompressed.resize(uncompressedLength); |
110 uncompressed.clear(); | 110 uncompressed.clear(); |
111 | 111 |
112 switch (error) | 112 switch (error) |
113 { | 113 { |
114 case Z_DATA_ERROR: | 114 case Z_DATA_ERROR: |
115 throw PalanthirException("Zlib: Corrupted or incomplete compressed buffer"); | 115 throw OrthancException("Zlib: Corrupted or incomplete compressed buffer"); |
116 | 116 |
117 case Z_MEM_ERROR: | 117 case Z_MEM_ERROR: |
118 throw PalanthirException(ErrorCode_NotEnoughMemory); | 118 throw OrthancException(ErrorCode_NotEnoughMemory); |
119 | 119 |
120 default: | 120 default: |
121 throw PalanthirException(ErrorCode_InternalError); | 121 throw OrthancException(ErrorCode_InternalError); |
122 } | 122 } |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |