Repository: nodejs/node
File: src/node_zlib.cc (C++)

Code before:
 public:
  void Close();
  void DoThreadPoolWork();
  CompressionError Init(std::string_view dictionary = {});
  CompressionError ResetStream();
  CompressionError SetParams(int key, uint32_t value);
  CompressionError GetErrorInfo() const;

  SET_MEMORY_INFO_NAME(BrotliEncoderContext)
  SET_SELF_SIZE(BrotliEncoderContext)
  SET_NO_MEMORY_INFO()  // state_ is covered through allocation tracking.

 private:
  bool last_result_ = false;
  DeleteFnPtr<BrotliEncoderState, BrotliEncoderDestroyInstance> state_;
  DeleteFnPtr<BrotliEncoderPreparedDictionary,
              BrotliEncoderDestroyPreparedDictionary> prepared_dictionary_;
  // Dictionary data must remain valid while the prepared dictionary is alive.
  std::vector<uint8_t> dictionary_;
};

class BrotliDecoderContext final : public BrotliContext {
 public:
  void Close();
  void DoThreadPoolWork();
  CompressionError Init(std::string_view dictionary = {});
  CompressionError ResetStream();
  CompressionError SetParams(int key, uint32_t value);
  CompressionError GetErrorInfo() const;

  SET_MEMORY_INFO_NAME(BrotliDecoderContext)
  SET_SELF_SIZE(BrotliDecoderContext)
  SET_NO_MEMORY_INFO()  // state_ is covered through allocation tracking.

 private:
  BrotliDecoderResult last_result_ = BROTLI_DECODER_RESULT_SUCCESS;
  BrotliDecoderErrorCode error_ = BROTLI_DECODER_NO_ERROR;
  std::string error_string_;
  DeleteFnPtr<BrotliDecoderState, BrotliDecoderDestroyInstance> state_;
  // Dictionary data must remain valid for the lifetime of the decoder.
  std::vector<uint8_t> dictionary_;
};

class ZstdContext : public MemoryRetainer {
 public:
  ZstdContext() = default;

  // Streaming-related, should be available for all compression libraries:
  void SetBuffers(const char* in, uint32_t in_len, char* out, uint32_t out_len);
  void SetFlush(int flush);
  void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;

Review comment (bug):
This didn't feel important enough to request an update, but since the linter is failing anyway – if this were 

```suggestion
  CompressionError Init(std::vector<uint8_t>&& dictionary = {});
```

the ownership semantics would be a bit clearer (i.e. it becomes obvious that this class will take ownership of the argument, instead of the `std::string_view` case where that's less clear)

Code after:
 public:
  void Close();
  void DoThreadPoolWork();
  CompressionError Init(std::vector<uint8_t>&& dictionary = {});
  CompressionError ResetStream();
  CompressionError SetParams(int key, uint32_t value);
  CompressionError GetErrorInfo() const;

  SET_MEMORY_INFO_NAME(BrotliEncoderContext)
  SET_SELF_SIZE(BrotliEncoderContext)
  SET_NO_MEMORY_INFO()  // state_ is covered through allocation tracking.

 private:
  bool last_result_ = false;
  DeleteFnPtr<BrotliEncoderState, BrotliEncoderDestroyInstance> state_;
  DeleteFnPtr<BrotliEncoderPreparedDictionary,
              BrotliEncoderDestroyPreparedDictionary>
      prepared_dictionary_;
  // Dictionary data must remain valid while the prepared dictionary is alive.
  std::vector<uint8_t> dictionary_;
};

class BrotliDecoderContext final : public BrotliContext {
 public:
  void Close();
  void DoThreadPoolWork();
  CompressionError Init(std::vector<uint8_t>&& dictionary = {});
  CompressionError ResetStream();
  CompressionError SetParams(int key, uint32_t value);
  CompressionError GetErrorInfo() const;

  SET_MEMORY_INFO_NAME(BrotliDecoderContext)
  SET_SELF_SIZE(BrotliDecoderContext)
  SET_NO_MEMORY_INFO()  // state_ is covered through allocation tracking.

 private:
  BrotliDecoderResult last_result_ = BROTLI_DECODER_RESULT_SUCCESS;
  BrotliDecoderErrorCode error_ = BROTLI_DECODER_NO_ERROR;
  std::string error_string_;
  DeleteFnPtr<BrotliDecoderState, BrotliDecoderDestroyInstance> state_;
  // Dictionary data must remain valid for the lifetime of the decoder.
  std::vector<uint8_t> dictionary_;
};

class ZstdContext : public MemoryRetainer {
 public:
  ZstdContext() = default;

  // Streaming-related, should be available for all compression libraries:
  void SetBuffers(const char* in, uint32_t in_len, char* out, uint32_t out_len);
  void SetFlush(int flush);