annotate OrthancFramework/Sources/Compression/HierarchicalZipWriter.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
25 #include "../PrecompiledHeaders.h"
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "HierarchicalZipWriter.h"
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../Toolbox.h"
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../OrthancException.h"
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/lexical_cast.hpp>
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 std::string HierarchicalZipWriter::Index::KeepAlphanumeric(const std::string& source)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 std::string result;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 bool lastSpace = false;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 result.reserve(source.size());
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 for (size_t i = 0; i < source.size(); i++)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
44 char c = source[i];
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
45 if (c == '^')
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
46 c = ' ';
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
47
1334
7f0aa3c0f659 code improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
48 if (c <= 127 &&
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
49 c >= 0)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
51 if (isspace(c))
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if (!lastSpace)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 lastSpace = true;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 result.push_back(' ');
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
59 else if (isalnum(c) ||
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
60 c == '.' ||
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
61 c == '_')
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
63 result.push_back(c);
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 lastSpace = false;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 return Toolbox::StripSpaces(result);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 std::string HierarchicalZipWriter::Index::GetCurrentDirectoryPath() const
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 std::string result;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 Stack::const_iterator it = stack_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
77 ++it; // Skip the root node (to avoid absolute paths)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 while (it != stack_.end())
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 result += (*it)->name_ + "/";
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
82 ++it;
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return result;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 std::string HierarchicalZipWriter::Index::EnsureUniqueFilename(const char* filename)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 std::string standardized = KeepAlphanumeric(filename);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 Directory& d = *stack_.back();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 Directory::Content::iterator it = d.content_.find(standardized);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 if (it == d.content_.end())
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 d.content_[standardized] = 1;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 return standardized;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 else
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 it->second++;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return standardized + "-" + boost::lexical_cast<std::string>(it->second);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 HierarchicalZipWriter::Index::Index()
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 stack_.push_back(new Directory);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 HierarchicalZipWriter::Index::~Index()
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
114 for (Stack::iterator it = stack_.begin(); it != stack_.end(); ++it)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 delete *it;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
120 bool HierarchicalZipWriter::Index::IsRoot() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
121 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
122 return stack_.size() == 1;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
123 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
124
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
125 std::string HierarchicalZipWriter::Index::OpenFile(const char* name)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 return GetCurrentDirectoryPath() + EnsureUniqueFilename(name);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
130 void HierarchicalZipWriter::Index::OpenDirectory(const char* name)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 std::string d = EnsureUniqueFilename(name);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 // Push the new directory onto the stack
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 stack_.push_back(new Directory);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 stack_.back()->name_ = d;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 void HierarchicalZipWriter::Index::CloseDirectory()
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (IsRoot())
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 // Cannot close the root node
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 throw OrthancException(ErrorCode_BadSequenceOfCalls);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 delete stack_.back();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 stack_.pop_back();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 HierarchicalZipWriter::HierarchicalZipWriter(const char* path)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 writer_.SetOutputPath(path);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 writer_.Open();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
158
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
159 HierarchicalZipWriter::HierarchicalZipWriter(ZipWriter::IOutputStream* stream,
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
160 bool isZip64)
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
161 {
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
162 writer_.AcquireOutputStream(stream, isZip64);
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
163 writer_.Open();
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
165
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
166
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 HierarchicalZipWriter::~HierarchicalZipWriter()
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 writer_.Close();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4296
diff changeset
172 void HierarchicalZipWriter::SetZip64(bool isZip64)
4296
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
173 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
174 writer_.SetZip64(isZip64);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
175 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
176
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
177 bool HierarchicalZipWriter::IsZip64() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
178 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
179 return writer_.IsZip64();
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
180 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
181
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
182 void HierarchicalZipWriter::SetCompressionLevel(uint8_t level)
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
183 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
184 writer_.SetCompressionLevel(level);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
185 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
186
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
187 uint8_t HierarchicalZipWriter::GetCompressionLevel() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
188 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
189 return writer_.GetCompressionLevel();
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
190 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
191
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
192 void HierarchicalZipWriter::SetAppendToExisting(bool append)
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
193 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
194 writer_.SetAppendToExisting(append);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
195 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
196
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
197 bool HierarchicalZipWriter::IsAppendToExisting() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
198 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
199 return writer_.IsAppendToExisting();
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
200 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
201
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
202 void HierarchicalZipWriter::OpenFile(const char* name)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
204 std::string p = indexer_.OpenFile(name);
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
205 writer_.OpenFile(p.c_str());
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
208 void HierarchicalZipWriter::OpenDirectory(const char* name)
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 248
diff changeset
210 indexer_.OpenDirectory(name);
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 void HierarchicalZipWriter::CloseDirectory()
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 indexer_.CloseDirectory();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
4296
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
217
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
218 std::string HierarchicalZipWriter::GetCurrentDirectoryPath() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
219 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
220 return indexer_.GetCurrentDirectoryPath();
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
221 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
222
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
223 void HierarchicalZipWriter::Write(const void *data, size_t length)
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
224 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
225 writer_.Write(data, length);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
226 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
227
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
228 void HierarchicalZipWriter::Write(const std::string &data)
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
229 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
230 writer_.Write(data);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
231 }
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
232
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
233 HierarchicalZipWriter* HierarchicalZipWriter::CreateToMemory(std::string& target,
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
234 bool isZip64)
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
235 {
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
236 return new HierarchicalZipWriter(new ZipWriter::MemoryStream(target), isZip64);
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
237 }
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
238
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
239 void HierarchicalZipWriter::CancelStream()
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
240 {
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
241 writer_.CancelStream();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
242 }
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
243
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
244 void HierarchicalZipWriter::Close()
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
245 {
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
246 writer_.Close();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
247 }
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
248
4673
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4672
diff changeset
249 uint64_t HierarchicalZipWriter::GetArchiveSize() const
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
250 {
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
251 return writer_.GetArchiveSize();
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
252 }
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }