-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define and expose user-defined error handler #156
Changes from all commits
6736522
6a6268f
6f65450
16fc052
11cbf4d
0bacb0b
e0cdedc
ad52453
354b418
e3e2a66
b0df2a5
dde5462
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,6 @@ struct zip_source; | |
#define LIBZIPPP_DEFAULT_CHUNK_SIZE 524288 | ||
#define LIBZIPPP_DEFAULT_PROGRESSION_PRECISION 0.5 | ||
|
||
// allow custom debug handling when errors occurs in libzippp | ||
#define LIBZIPPP_ERROR_DEBUG(str, errormsg) fprintf(stderr, (str"\n"), (errormsg)); | ||
|
||
//libzip documentation | ||
//- http://www.nih.at/libzip/libzip.html | ||
//- http://slash.developpez.com/tutoriels/c/utilisation-libzip/ | ||
|
@@ -99,14 +96,22 @@ struct zip_source; | |
namespace libzippp { | ||
class ZipEntry; | ||
class ZipProgressListener; | ||
|
||
|
||
/** | ||
* User-defined error-handler. | ||
* See https://libzip.org/documentation/zip_error_system_type.html | ||
*/ | ||
using ErrorHandlerCallback = std::function<void(const std::string& message, | ||
int zip_error_code, | ||
int system_error_code)>; | ||
|
||
/** | ||
* Represents a ZIP archive. This class provides useful methods to handle an archive | ||
* content. It is simply a wrapper around libzip. | ||
*/ | ||
class LIBZIPPP_API ZipArchive { | ||
public: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let this empty line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
/** | ||
* Defines how the zip file must be open. | ||
* NotOpen is a special mode where the file is not open. | ||
|
@@ -526,6 +531,10 @@ namespace libzippp { | |
inline double getProgressPrecision(void) const { return progressPrecision; } | ||
void setProgressPrecision(double p) { progressPrecision = p; } | ||
|
||
void setErrorHandlerCallback(const ErrorHandlerCallback& callback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, see README.md |
||
errorHandlingCallback = callback; | ||
} | ||
|
||
private: | ||
std::string path; | ||
zip* zipHandle; | ||
|
@@ -538,6 +547,9 @@ namespace libzippp { | |
|
||
void** bufferData; | ||
libzippp_uint64 bufferLength; | ||
|
||
// User-defined error handler | ||
ErrorHandlerCallback errorHandlingCallback; | ||
|
||
//open from in-memory data | ||
bool openBuffer(void** buffer, libzippp_uint32 sz, OpenMode mode=ReadOnly, bool checkConsistency=false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty line before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done