Mercurial > hg > orthanc
annotate Core/FileStorage/CompressedFileStorageAccessor.cpp @ 676:aa5ca7a2166f
experiments with pixel data
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 03 Jan 2014 17:49:31 +0100 |
parents | bdd72233b105 |
children | 2d0a347e8cfc |
rev | line source |
---|---|
221 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
398 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
221 | 4 * Belgium |
5 * | |
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 | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "CompressedFileStorageAccessor.h" | |
34 | |
35 #include "../OrthancException.h" | |
36 #include "FileStorageAccessor.h" | |
37 #include "../HttpServer/BufferHttpSender.h" | |
38 | |
39 namespace Orthanc | |
40 { | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
41 FileInfo CompressedFileStorageAccessor::WriteInternal(const void* data, |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
42 size_t size, |
233 | 43 FileContentType type) |
221 | 44 { |
45 switch (compressionType_) | |
46 { | |
47 case CompressionType_None: | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
48 { |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
49 std::string uuid = storage_.Create(data, size); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
50 return FileInfo(uuid, type, size); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
51 } |
221 | 52 |
53 case CompressionType_Zlib: | |
54 { | |
55 std::string compressed; | |
56 zlib_.Compress(compressed, data, size); | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
57 std::string uuid = storage_.Create(compressed); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
58 return FileInfo(uuid, type, size, |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
59 CompressionType_Zlib, compressed.size()); |
221 | 60 } |
61 | |
62 default: | |
63 throw OrthancException(ErrorCode_NotImplemented); | |
64 } | |
65 } | |
66 | |
67 CompressedFileStorageAccessor::CompressedFileStorageAccessor(FileStorage& storage) : | |
68 storage_(storage) | |
69 { | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
70 compressionType_ = CompressionType_None; |
221 | 71 } |
72 | |
73 void CompressedFileStorageAccessor::Read(std::string& content, | |
74 const std::string& uuid) | |
75 { | |
76 switch (compressionType_) | |
77 { | |
78 case CompressionType_None: | |
79 storage_.ReadFile(content, uuid); | |
80 break; | |
81 | |
82 case CompressionType_Zlib: | |
83 { | |
84 std::string compressed; | |
85 storage_.ReadFile(compressed, uuid); | |
86 zlib_.Uncompress(content, compressed); | |
87 break; | |
88 } | |
89 | |
90 default: | |
91 throw OrthancException(ErrorCode_NotImplemented); | |
92 } | |
93 } | |
94 | |
95 HttpFileSender* CompressedFileStorageAccessor::ConstructHttpFileSender(const std::string& uuid) | |
96 { | |
97 switch (compressionType_) | |
98 { | |
99 case CompressionType_None: | |
100 { | |
101 FileStorageAccessor uncompressedAccessor(storage_); | |
102 return uncompressedAccessor.ConstructHttpFileSender(uuid); | |
103 } | |
104 | |
105 case CompressionType_Zlib: | |
106 { | |
107 std::string compressed; | |
108 storage_.ReadFile(compressed, uuid); | |
109 | |
110 std::auto_ptr<BufferHttpSender> sender(new BufferHttpSender); | |
111 zlib_.Uncompress(sender->GetBuffer(), compressed); | |
112 | |
113 return sender.release(); | |
114 } | |
115 | |
116 default: | |
117 throw OrthancException(ErrorCode_NotImplemented); | |
118 } | |
119 } | |
120 } |