diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /modules/libjar/zipwriter/nsDeflateConverter.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | modules/libjar/zipwriter/nsDeflateConverter.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/libjar/zipwriter/nsDeflateConverter.h b/modules/libjar/zipwriter/nsDeflateConverter.h new file mode 100644 index 0000000000..4a82299c1c --- /dev/null +++ b/modules/libjar/zipwriter/nsDeflateConverter.h @@ -0,0 +1,57 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _nsDeflateConverter_h_ +#define _nsDeflateConverter_h_ + +#include "nsIStreamConverter.h" +#include "nsCOMPtr.h" +#include "zlib.h" +#include "mozilla/Attributes.h" + +#define DEFLATECONVERTER_CID \ + { \ + 0x461cd5dd, 0x73c6, 0x47a4, { \ + 0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61 \ + } \ + } + +class nsDeflateConverter final : public nsIStreamConverter { + public: + static constexpr size_t kZipBufLen = (4 * 1024 - 1); + + NS_DECL_ISUPPORTS + NS_DECL_NSIREQUESTOBSERVER + NS_DECL_NSISTREAMLISTENER + NS_DECL_NSISTREAMCONVERTER + + nsDeflateConverter() : mWrapMode(WRAP_NONE), mOffset(0), mZstream() { + // 6 is Z_DEFAULT_COMPRESSION but we need the actual value + mLevel = 6; + } + + explicit nsDeflateConverter(int32_t level) + : mWrapMode(WRAP_NONE), mOffset(0), mZstream() { + mLevel = level; + } + + private: + ~nsDeflateConverter() {} + + enum WrapMode { WRAP_ZLIB, WRAP_GZIP, WRAP_NONE }; + + WrapMode mWrapMode; + uint64_t mOffset; + int32_t mLevel; + nsCOMPtr<nsIStreamListener> mListener; + nsCOMPtr<nsISupports> mContext; + z_stream mZstream; + unsigned char mWriteBuffer[kZipBufLen]; + + nsresult Init(); + nsresult PushAvailableData(nsIRequest* aRequest); +}; + +#endif |