fs/io/GzipOutputStream: use C++ exceptions in constructor
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
#include "config.h"
|
||||
#include "GzipOutputStream.hxx"
|
||||
#include "lib/zlib/Domain.hxx"
|
||||
#include "lib/zlib/Error.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
|
||||
GzipOutputStream::GzipOutputStream(OutputStream &_next, Error &error)
|
||||
GzipOutputStream::GzipOutputStream(OutputStream &_next) throw(ZlibError)
|
||||
:next(_next)
|
||||
{
|
||||
z.next_in = nullptr;
|
||||
@@ -38,16 +38,13 @@ GzipOutputStream::GzipOutputStream(OutputStream &_next, Error &error)
|
||||
int result = deflateInit2(&z, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
||||
windowBits | gzip_encoding,
|
||||
8, Z_DEFAULT_STRATEGY);
|
||||
if (result != Z_OK) {
|
||||
z.opaque = this;
|
||||
error.Set(zlib_domain, result, zError(result));
|
||||
}
|
||||
if (result != Z_OK)
|
||||
throw ZlibError(result);
|
||||
}
|
||||
|
||||
GzipOutputStream::~GzipOutputStream()
|
||||
{
|
||||
if (IsDefined())
|
||||
deflateEnd(&z);
|
||||
deflateEnd(&z);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@@ -22,13 +22,13 @@
|
||||
|
||||
#include "check.h"
|
||||
#include "OutputStream.hxx"
|
||||
#include "lib/zlib/Error.hxx"
|
||||
#include "Compiler.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <zlib.h>
|
||||
|
||||
class Error;
|
||||
class Domain;
|
||||
|
||||
/**
|
||||
* A filter that compresses data written to it using zlib, forwarding
|
||||
@@ -43,20 +43,11 @@ class GzipOutputStream final : public OutputStream {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct the filter. Call IsDefined() to check whether
|
||||
* the constructor has succeeded. If not, #error will hold
|
||||
* information about the failure.
|
||||
* Construct the filter.
|
||||
*/
|
||||
GzipOutputStream(OutputStream &_next, Error &error);
|
||||
GzipOutputStream(OutputStream &_next) throw(ZlibError);
|
||||
~GzipOutputStream();
|
||||
|
||||
/**
|
||||
* Check whether the constructor has succeeded.
|
||||
*/
|
||||
bool IsDefined() const {
|
||||
return z.opaque == nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the file and write all data remaining in zlib's
|
||||
* output buffer.
|
||||
|
Reference in New Issue
Block a user