comparison Core/Compression/ZlibCompressor.cpp @ 50:a15e90e5d6fc

rename in code
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Sep 2012 15:50:12 +0200
parents 3959d33612cc
children c996319e90bc
comparison
equal deleted inserted replaced
49:e1a3ae0dadf3 50:a15e90e5d6fc
1 /** 1 /**
2 * Palantir - A Lightweight, RESTful DICOM Store 2 * Palanthir - 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 "../PalantirException.h" 26 #include "../PalanthirException.h"
27 27
28 namespace Palantir 28 namespace Palanthir
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 PalantirException("Zlib compression level must be between 0 (no compression) and 9 (highest compression"); 34 throw PalanthirException("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 PalantirException(ErrorCode_NotEnoughMemory); 73 throw PalanthirException(ErrorCode_NotEnoughMemory);
74 74
75 default: 75 default:
76 throw PalantirException(ErrorCode_InternalError); 76 throw PalanthirException(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 PalantirException("Zlib: The compressed buffer is ill-formed"); 94 throw PalanthirException("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 PalantirException("Zlib: Corrupted or incomplete compressed buffer"); 115 throw PalanthirException("Zlib: Corrupted or incomplete compressed buffer");
116 116
117 case Z_MEM_ERROR: 117 case Z_MEM_ERROR:
118 throw PalantirException(ErrorCode_NotEnoughMemory); 118 throw PalanthirException(ErrorCode_NotEnoughMemory);
119 119
120 default: 120 default:
121 throw PalantirException(ErrorCode_InternalError); 121 throw PalanthirException(ErrorCode_InternalError);
122 } 122 }
123 } 123 }
124 } 124 }
125 } 125 }