OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Zipper Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Zipper.hpp>

Collaboration diagram for Slic3r::Zipper:

Classes

class  Impl

Public Types

enum  e_compression { NO_COMPRESSION , FAST_COMPRESSION , TIGHT_COMPRESSION }

Public Member Functions

 Zipper (const std::string &zipfname, e_compression level=FAST_COMPRESSION)
 ~Zipper ()
 Zipper (const Zipper &)=delete
Zipper & operator= (const Zipper &)=delete
 Zipper (Zipper &&m)
Zipper & operator= (Zipper &&m)
void add_entry (const std::string &name)
 Adding an entry means a file inside the new archive. Name param is the name of the new file. To create directories, append a forward slash. The previous entry is finished (see finish_entry).
void add_entry (const std::string &name, const void *data, size_t bytes)
 Add a new binary file entry with an instantly given byte buffer. This method throws exactly like finish_entry() does.
template<class T>
std::enable_if< std::is_arithmetic< T >::value, Zipper & >::type operator<< (T &&val)
template<class T>
std::enable_if<!std::is_arithmetic< T >::value, Zipper & >::type operator<< (T &&val)
void finish_entry ()
 Finishing an entry means that subsequent writes will no longer be appended to the previous entry. They will be written into the internal buffer and ones an entry is added, the buffer will bind to the new entry If the buffer was written, but no entry was added, the buffer will be cleared after this call.
void finalize ()
const std::string & get_filename () const

Private Attributes

std::unique_ptr< Impl > m_impl
std::string m_data
std::string m_entry
e_compression m_compression

Detailed Description

Member Enumeration Documentation

◆ e_compression

Enumerator
NO_COMPRESSION 
FAST_COMPRESSION 
TIGHT_COMPRESSION 
16 {
20 };
@ FAST_COMPRESSION
Definition Zipper.hpp:18
@ NO_COMPRESSION
Definition Zipper.hpp:17
@ TIGHT_COMPRESSION
Definition Zipper.hpp:19

Constructor & Destructor Documentation

◆ Zipper() [1/3]

Slic3r::Zipper::Zipper ( const std::string & zipfname,
e_compression level = FAST_COMPRESSION )
explicit
48{
49 m_impl.reset(new Impl());
50
51 m_compression = compression;
52 m_impl->m_zipname = zipfname;
53
54 memset(&m_impl->arch, 0, sizeof(m_impl->arch));
55
56 if (!open_zip_writer(&m_impl->arch, zipfname)) {
57 m_impl->blow_up();
58 }
59}
Definition Zipper.cpp:26
e_compression m_compression
Definition Zipper.hpp:27
std::unique_ptr< Impl > m_impl
Definition Zipper.hpp:24
bool open_zip_writer(mz_zip_archive *zip, const std::string &fname)
Definition miniz_extension.cpp:124

References m_compression, m_impl, and Slic3r::open_zip_writer().

Referenced by Zipper(), Zipper(), operator<<(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Zipper()

Slic3r::Zipper::~Zipper ( )
62{
63 if(m_impl->is_alive()) {
64 // Flush the current entry if not finished yet.
65 try { finish_entry(); } catch(...) {
66 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
67 }
68
69 if(!mz_zip_writer_finalize_archive(&m_impl->arch))
70 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
71 }
72
73 // The file should be closed no matter what...
74 if(!close_zip_writer(&m_impl->arch))
75 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
76}
void finish_entry()
Finishing an entry means that subsequent writes will no longer be appended to the previous entry....
Definition Zipper.cpp:119
bool close_zip_writer(mz_zip_archive *zip)
Definition miniz_extension.cpp:130

References Slic3r::close_zip_writer(), finish_entry(), and m_impl.

Here is the call graph for this function:

◆ Zipper() [2/3]

Slic3r::Zipper::Zipper ( const Zipper & )
delete

References Zipper().

Here is the call graph for this function:

◆ Zipper() [3/3]

Slic3r::Zipper::Zipper ( Zipper && m)
78 :
79 m_impl(std::move(m.m_impl)),
80 m_data(std::move(m.m_data)),
81 m_entry(std::move(m.m_entry)),
82 m_compression(m.m_compression) {}
std::string m_entry
Definition Zipper.hpp:26
std::string m_data
Definition Zipper.hpp:25

References Zipper(), m_compression, m_data, m_entry, and m_impl.

Here is the call graph for this function:

Member Function Documentation

◆ add_entry() [1/2]

void Slic3r::Zipper::add_entry ( const std::string & name)

Adding an entry means a file inside the new archive. Name param is the name of the new file. To create directories, append a forward slash. The previous entry is finished (see finish_entry).

93{
94 if(!m_impl->is_alive()) return;
95
96 finish_entry(); // finish previous business
97 m_entry = name;
98}

References finish_entry(), m_entry, and m_impl.

Referenced by Slic3r::PresetBundle::backup_user_folder_to_zip(), Slic3r::SL1Archive::export_print(), and Slic3r::write_thumbnail().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_entry() [2/2]

void Slic3r::Zipper::add_entry ( const std::string & name,
const void * data,
size_t bytes )

Add a new binary file entry with an instantly given byte buffer. This method throws exactly like finish_entry() does.

101{
102 if(!m_impl->is_alive()) return;
103
104 finish_entry();
105 mz_uint cmpr = MZ_NO_COMPRESSION;
106 switch (m_compression) {
107 case NO_COMPRESSION: cmpr = MZ_NO_COMPRESSION; break;
108 case FAST_COMPRESSION: cmpr = MZ_BEST_SPEED; break;
109 case TIGHT_COMPRESSION: cmpr = MZ_BEST_COMPRESSION; break;
110 }
111
112 if(!mz_zip_writer_add_mem(&m_impl->arch, name.c_str(), data, l, cmpr))
113 m_impl->blow_up();
114
115 m_entry.clear();
116 m_data.clear();
117}

References FAST_COMPRESSION, finish_entry(), m_compression, m_data, m_entry, m_impl, NO_COMPRESSION, and TIGHT_COMPRESSION.

Here is the call graph for this function:

◆ finalize()

void Slic3r::Zipper::finalize ( )
143{
144 finish_entry();
145
146 if(m_impl->is_alive()) if(!mz_zip_writer_finalize_archive(&m_impl->arch))
147 m_impl->blow_up();
148}

References finish_entry(), and m_impl.

Referenced by Slic3r::PresetBundle::backup_user_folder_to_zip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_entry()

void Slic3r::Zipper::finish_entry ( )

Finishing an entry means that subsequent writes will no longer be appended to the previous entry. They will be written into the internal buffer and ones an entry is added, the buffer will bind to the new entry If the buffer was written, but no entry was added, the buffer will be cleared after this call.

This method will throw a runtime exception if an error occures. The entry will still be open (with the data intact) but the state of the file is up to minz after the erroneous write.

120{
121 if(!m_impl->is_alive()) return;
122
123 if(!m_data.empty() && !m_entry.empty()) {
124 mz_uint compression = MZ_NO_COMPRESSION;
125
126 switch (m_compression) {
127 case NO_COMPRESSION: compression = MZ_NO_COMPRESSION; break;
128 case FAST_COMPRESSION: compression = MZ_BEST_SPEED; break;
129 case TIGHT_COMPRESSION: compression = MZ_BEST_COMPRESSION; break;
130 }
131
132 if(!mz_zip_writer_add_mem(&m_impl->arch, m_entry.c_str(),
133 m_data.c_str(),
134 m_data.size(),
135 compression)) m_impl->blow_up();
136 }
137
138 m_data.clear();
139 m_entry.clear();
140}

References FAST_COMPRESSION, m_compression, m_data, m_entry, m_impl, NO_COMPRESSION, and TIGHT_COMPRESSION.

Referenced by ~Zipper(), add_entry(), add_entry(), and finalize().

Here is the caller graph for this function:

◆ get_filename()

const std::string & Slic3r::Zipper::get_filename ( ) const
151{
152 return m_impl->m_zipname;
153}

References m_impl.

Referenced by Slic3r::SL1Archive::export_print().

Here is the caller graph for this function:

◆ operator<<() [1/2]

template<class T>
std::enable_if<!std::is_arithmetic< T >::value, Zipper & >::type Slic3r::Zipper::operator<< ( T && val)
inline
70 {
71 if(m_data.empty()) m_data = std::forward<T>(val);
72 else m_data.append(val);
73 return *this;
74 }

References Zipper(), and m_data.

Here is the call graph for this function:

◆ operator<<() [2/2]

template<class T>
std::enable_if< std::is_arithmetic< T >::value, Zipper & >::type Slic3r::Zipper::operator<< ( T && val)
inline
62 {
63 return this->operator<<(std::to_string(std::forward<T>(val)));
64 }

References Zipper().

Here is the call graph for this function:

◆ operator=() [1/2]

Zipper & Slic3r::Zipper::operator= ( const Zipper & )
delete

References Zipper().

Here is the call graph for this function:

◆ operator=() [2/2]

Zipper & Slic3r::Zipper::operator= ( Zipper && m)
84 {
85 m_impl = std::move(m.m_impl);
86 m_data = std::move(m.m_data);
87 m_entry = std::move(m.m_entry);
88 m_compression = m.m_compression;
89 return *this;
90}

References Zipper(), m_compression, m_data, m_entry, and m_impl.

Here is the call graph for this function:

Member Data Documentation

◆ m_compression

e_compression Slic3r::Zipper::m_compression
private

◆ m_data

std::string Slic3r::Zipper::m_data
private

◆ m_entry

std::string Slic3r::Zipper::m_entry
private

◆ m_impl

std::unique_ptr<Impl> Slic3r::Zipper::m_impl
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Zipper.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Zipper.cpp