Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / base / ZLibHelper.h
blob86de8c4086458e49d4494a595cd386ed73396abd
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_ZLIBHELPER_H_
8 #define DOM_ZLIBHELPER_H_
10 #include "js/TypeDecls.h"
11 #include "zlib.h"
13 #include "mozilla/dom/CompressionStreamBinding.h"
15 namespace mozilla::dom {
17 // From the docs in
18 // https://searchfox.org/mozilla-central/source/modules/zlib/src/zlib.h
19 inline int8_t ZLibWindowBits(CompressionFormat format) {
20 switch (format) {
21 case CompressionFormat::Deflate:
22 // The windowBits parameter is the base two logarithm of the window size
23 // (the size of the history buffer). It should be in the range 8..15 for
24 // this version of the library. Larger values of this parameter result
25 // in better compression at the expense of memory usage.
26 return 15;
27 case CompressionFormat::Deflate_raw:
28 // windowBits can also be –8..–15 for raw deflate. In this case,
29 // -windowBits determines the window size.
30 return -15;
31 case CompressionFormat::Gzip:
32 // windowBits can also be greater than 15 for optional gzip encoding.
33 // Add 16 to windowBits to write a simple gzip header and trailer around
34 // the compressed data instead of a zlib wrapper.
35 return 31;
36 default:
37 MOZ_ASSERT_UNREACHABLE("Unknown compression format");
38 return 0;
42 enum ZLibFlush : uint8_t { No = Z_NO_FLUSH, Yes = Z_FINISH };
44 } // namespace mozilla::dom
46 #endif // DOM_ZLIBHELPER_H_