tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FormatZlib.h (2775B)


      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/. */
      6 
      7 #ifndef DOM_COMPRESSION_FORMATZLIB_H_
      8 #define DOM_COMPRESSION_FORMATZLIB_H_
      9 
     10 #include "BaseAlgorithms.h"
     11 #include "mozilla/dom/TransformerCallbackHelpers.h"
     12 #include "zlib.h"
     13 
     14 // See the zlib manual in https://www.zlib.net/manual.html or in
     15 // https://searchfox.org/mozilla-central/source/modules/zlib/src/zlib.h
     16 
     17 namespace mozilla::dom {
     18 enum class CompressionFormat : uint8_t;
     19 }
     20 
     21 namespace mozilla::dom::compression {
     22 
     23 class ZLibCompressionStreamAlgorithms : public CompressionStreamAlgorithms {
     24 public:
     25  NS_DECL_ISUPPORTS_INHERITED
     26  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ZLibCompressionStreamAlgorithms,
     27                                           CompressionStreamAlgorithms)
     28 
     29  static Result<already_AddRefed<ZLibCompressionStreamAlgorithms>, nsresult>
     30  Create(CompressionFormat format);
     31 
     32 private:
     33  ZLibCompressionStreamAlgorithms() = default;
     34 
     35  [[nodiscard]] nsresult Init(CompressionFormat format);
     36 
     37  // Shared by:
     38  // https://wicg.github.io/compression/#compress-and-enqueue-a-chunk
     39  // https://wicg.github.io/compression/#compress-flush-and-enqueue
     40  void Compress(JSContext* aCx, Span<const uint8_t> aInput,
     41                JS::MutableHandleVector<JSObject*> aOutput, Flush aFlush,
     42                ErrorResult& aRv) override;
     43 
     44  ~ZLibCompressionStreamAlgorithms() override;
     45 
     46  z_stream mZStream = {};
     47 };
     48 
     49 class ZLibDecompressionStreamAlgorithms : public DecompressionStreamAlgorithms {
     50 public:
     51  NS_DECL_ISUPPORTS_INHERITED
     52  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ZLibDecompressionStreamAlgorithms,
     53                                           DecompressionStreamAlgorithms)
     54 
     55  static Result<already_AddRefed<ZLibDecompressionStreamAlgorithms>, nsresult>
     56  Create(CompressionFormat format);
     57 
     58 private:
     59  ZLibDecompressionStreamAlgorithms() = default;
     60 
     61  [[nodiscard]] nsresult Init(CompressionFormat format);
     62 
     63  // Shared by:
     64  // https://wicg.github.io/compression/#decompress-and-enqueue-a-chunk
     65  // https://wicg.github.io/compression/#decompress-flush-and-enqueue
     66  // All data errors throw TypeError by step 2: If this results in an error,
     67  // then throw a TypeError.
     68  bool Decompress(JSContext* aCx, Span<const uint8_t> aInput,
     69                  JS::MutableHandleVector<JSObject*> aOutput, Flush aFlush,
     70                  ErrorResult& aRv) override;
     71 
     72  ~ZLibDecompressionStreamAlgorithms() override;
     73 
     74  z_stream mZStream = {};
     75 };
     76 
     77 }  // namespace mozilla::dom::compression
     78 
     79 #endif  // DOM_COMPRESSION_FORMATZLIB_H_