@@ -257,7 +257,7 @@ class BrotliEncoderContext final : public BrotliContext {
257257 public:
258258 void Close ();
259259 void DoThreadPoolWork ();
260- CompressionError Init (std::string_view dictionary = {});
260+ CompressionError Init (std::vector< uint8_t >&& dictionary = {});
261261 CompressionError ResetStream ();
262262 CompressionError SetParams (int key, uint32_t value);
263263 CompressionError GetErrorInfo () const ;
@@ -279,7 +279,7 @@ class BrotliDecoderContext final : public BrotliContext {
279279 public:
280280 void Close ();
281281 void DoThreadPoolWork ();
282- CompressionError Init (std::string_view dictionary = {});
282+ CompressionError Init (std::vector< uint8_t >&& dictionary = {});
283283 CompressionError ResetStream ();
284284 CompressionError SetParams (int key, uint32_t value);
285285 CompressionError GetErrorInfo () const ;
@@ -849,19 +849,18 @@ class BrotliCompressionStream final :
849849 wrap->InitStream (write_result, write_js_callback);
850850
851851 AllocScope alloc_scope (wrap);
852- std::string_view dictionary;
853- ArrayBufferViewContents<char > contents;
852+ std::vector<uint8_t > dictionary;
854853 if (args.Length () == 4 && !args[3 ]->IsUndefined ()) {
855854 if (!args[3 ]->IsArrayBufferView ()) {
856855 THROW_ERR_INVALID_ARG_TYPE (
857856 wrap->env (), " dictionary must be an ArrayBufferView if provided" );
858857 return ;
859858 }
860- contents. ReadValue (args[3 ]);
861- dictionary = std::string_view (contents.data (), contents.length ());
859+ ArrayBufferViewContents< uint8_t > contents (args[3 ]);
860+ dictionary. assign (contents.data (), contents. data () + contents.length ());
862861 }
863862
864- CompressionError err = wrap->context ()->Init (dictionary);
863+ CompressionError err = wrap->context ()->Init (std::move ( dictionary) );
865864 if (err.IsError ()) {
866865 wrap->EmitError (err);
867866 // TODO(addaleax): Sometimes we generate better error codes in C++ land,
@@ -1412,7 +1411,7 @@ void BrotliEncoderContext::Close() {
14121411 mode_ = NONE;
14131412}
14141413
1415- CompressionError BrotliEncoderContext::Init (std::string_view dictionary) {
1414+ CompressionError BrotliEncoderContext::Init (std::vector< uint8_t >&& dictionary) {
14161415 brotli_alloc_func alloc = CompressionStreamMemoryOwner::AllocForBrotli;
14171416 brotli_free_func free = CompressionStreamMemoryOwner::FreeForZlib;
14181417 void * opaque =
@@ -1432,11 +1431,8 @@ CompressionError BrotliEncoderContext::Init(std::string_view dictionary) {
14321431
14331432 if (!dictionary.empty ()) {
14341433 // The dictionary data must remain valid for the lifetime of the prepared
1435- // dictionary, so copy it into a member vector.
1436- dictionary_.assign (
1437- reinterpret_cast <const uint8_t *>(dictionary.data ()),
1438- reinterpret_cast <const uint8_t *>(dictionary.data ()) +
1439- dictionary.size ());
1434+ // dictionary, so take ownership via move.
1435+ dictionary_ = std::move (dictionary);
14401436
14411437 prepared_dictionary_.reset (BrotliEncoderPrepareDictionary (
14421438 BROTLI_SHARED_DICTIONARY_RAW,
@@ -1513,7 +1509,7 @@ void BrotliDecoderContext::DoThreadPoolWork() {
15131509 }
15141510}
15151511
1516- CompressionError BrotliDecoderContext::Init (std::string_view dictionary) {
1512+ CompressionError BrotliDecoderContext::Init (std::vector< uint8_t >&& dictionary) {
15171513 brotli_alloc_func alloc = CompressionStreamMemoryOwner::AllocForBrotli;
15181514 brotli_free_func free = CompressionStreamMemoryOwner::FreeForZlib;
15191515 void * opaque =
@@ -1532,11 +1528,8 @@ CompressionError BrotliDecoderContext::Init(std::string_view dictionary) {
15321528
15331529 if (!dictionary.empty ()) {
15341530 // The dictionary data must remain valid for the lifetime of the decoder,
1535- // so copy it into a member vector.
1536- dictionary_.assign (
1537- reinterpret_cast <const uint8_t *>(dictionary.data ()),
1538- reinterpret_cast <const uint8_t *>(dictionary.data ()) +
1539- dictionary.size ());
1531+ // so take ownership via move.
1532+ dictionary_ = std::move (dictionary);
15401533
15411534 if (!BrotliDecoderAttachDictionary (state_.get (),
15421535 BROTLI_SHARED_DICTIONARY_RAW,
0 commit comments