Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::Zipper Class Reference

#include <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
 
Zipperoperator= (const Zipper &)=delete
 
 Zipper (Zipper &&m)
 
Zipperoperator= (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< Implm_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 
14 {
18 };
@ FAST_COMPRESSION
Definition Zipper.hpp:16
@ NO_COMPRESSION
Definition Zipper.hpp:15
@ TIGHT_COMPRESSION
Definition Zipper.hpp:17

Constructor & Destructor Documentation

◆ Zipper() [1/3]

Slic3r::Zipper::Zipper ( const std::string &  zipfname,
e_compression  level = FAST_COMPRESSION 
)
explicit
39{
40 m_impl.reset(new Impl());
41
42 m_compression = compression;
43 m_impl->m_zipname = zipfname;
44
45 memset(&m_impl->arch, 0, sizeof(m_impl->arch));
46
47 if (!open_zip_writer(&m_impl->arch, zipfname)) {
48 m_impl->blow_up();
49 }
50}
e_compression m_compression
Definition Zipper.hpp:25
std::unique_ptr< Impl > m_impl
Definition Zipper.hpp:22
bool open_zip_writer(mz_zip_archive *zip, const std::string &fname)
Definition miniz_extension.cpp:67

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

+ Here is the call graph for this function:

◆ ~Zipper()

Slic3r::Zipper::~Zipper ( )
53{
54 if(m_impl->is_alive()) {
55 // Flush the current entry if not finished yet.
56 try { finish_entry(); } catch(...) {
57 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
58 }
59
61 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
62 }
63
64 // The file should be closed no matter what...
65 if(!close_zip_writer(&m_impl->arch))
66 BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
67}
void finish_entry()
Finishing an entry means that subsequent writes will no longer be appended to the previous entry....
Definition Zipper.cpp:110
mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip)
Definition miniz.c:7462
bool close_zip_writer(mz_zip_archive *zip)
Definition miniz_extension.cpp:73
static char error[256]
Definition tga.cpp:50

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

+ Here is the call graph for this function:

◆ Zipper() [2/3]

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

◆ Zipper() [3/3]

Slic3r::Zipper::Zipper ( Zipper &&  m)
69 :
70 m_impl(std::move(m.m_impl)),
71 m_data(std::move(m.m_data)),
72 m_entry(std::move(m.m_entry)),
73 m_compression(m.m_compression) {}
std::string m_entry
Definition Zipper.hpp:24
std::string m_data
Definition Zipper.hpp:23

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)

84{
85 if(!m_impl->is_alive()) return;
86
87 finish_entry(); // finish previous business
88 m_entry = name;
89}

References finish_entry(), m_entry, and m_impl.

Referenced by 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.

92{
93 if(!m_impl->is_alive()) return;
94
97 switch (m_compression) {
98 case NO_COMPRESSION: cmpr = MZ_NO_COMPRESSION; break;
99 case FAST_COMPRESSION: cmpr = MZ_BEST_SPEED; break;
100 case TIGHT_COMPRESSION: cmpr = MZ_BEST_COMPRESSION; break;
101 }
102
103 if(!mz_zip_writer_add_mem(&m_impl->arch, name.c_str(), data, l, cmpr))
104 m_impl->blow_up();
105
106 m_entry.clear();
107 m_data.clear();
108}
mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags)
Definition miniz.c:5902
unsigned int mz_uint
Definition miniz.h:489
@ MZ_BEST_SPEED
Definition miniz.h:234
@ MZ_NO_COMPRESSION
Definition miniz.h:233
@ MZ_BEST_COMPRESSION
Definition miniz.h:235

References FAST_COMPRESSION, finish_entry(), m_compression, m_data, m_entry, m_impl, MZ_BEST_COMPRESSION, MZ_BEST_SPEED, MZ_NO_COMPRESSION, mz_zip_writer_add_mem(), NO_COMPRESSION, and TIGHT_COMPRESSION.

+ Here is the call graph for this function:

◆ finalize()

void Slic3r::Zipper::finalize ( )
134{
135 finish_entry();
136
137 if(m_impl->is_alive()) if(!mz_zip_writer_finalize_archive(&m_impl->arch))
138 m_impl->blow_up();
139}

References finish_entry(), m_impl, and mz_zip_writer_finalize_archive().

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

+ 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.

111{
112 if(!m_impl->is_alive()) return;
113
114 if(!m_data.empty() && !m_entry.empty()) {
115 mz_uint compression = MZ_NO_COMPRESSION;
116
117 switch (m_compression) {
118 case NO_COMPRESSION: compression = MZ_NO_COMPRESSION; break;
119 case FAST_COMPRESSION: compression = MZ_BEST_SPEED; break;
120 case TIGHT_COMPRESSION: compression = MZ_BEST_COMPRESSION; break;
121 }
122
123 if(!mz_zip_writer_add_mem(&m_impl->arch, m_entry.c_str(),
124 m_data.c_str(),
125 m_data.size(),
126 compression)) m_impl->blow_up();
127 }
128
129 m_data.clear();
130 m_entry.clear();
131}

References FAST_COMPRESSION, m_compression, m_data, m_entry, m_impl, MZ_BEST_COMPRESSION, MZ_BEST_SPEED, MZ_NO_COMPRESSION, mz_zip_writer_add_mem(), NO_COMPRESSION, and TIGHT_COMPRESSION.

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

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

◆ get_filename()

const std::string & Slic3r::Zipper::get_filename ( ) const
142{
143 return m_impl->m_zipname;
144}

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
60 {
61 return this->operator<<(std::to_string(std::forward<T>(val)));
62 }

◆ operator<<() [2/2]

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

References m_data.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Zipper & Slic3r::Zipper::operator= ( Zipper &&  m)
75 {
76 m_impl = std::move(m.m_impl);
77 m_data = std::move(m.m_data);
78 m_entry = std::move(m.m_entry);
79 m_compression = m.m_compression;
80 return *this;
81}

References m_compression, m_data, m_entry, and m_impl.

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: