Add TextEncoder and TextDecoder support
#5441
Draft
+5,794
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Add support for text encoding/decoding operations via a new
k6/experimental/encoding module. This brings the WHATWG Encoding API standard to k6, implementing theTextEncoderandTextDecoderinterfaces for converting between strings and byte arrays.This code is imported from https://github.com/oleiade/xk6-encoding with modifications to integrate it as a built-in experimental module.
Key Changes
k6/experimental/encodingwithTextEncoderandTextDecoderclassesTextEncoderTextDecoderwith configurable error handlinggolang.org/x/text v0.31.0examples/experimental/encoding.jsUsage example
Implementation limitations
As documented in the original xk6-encoding extension:
-
TextEncoderalways outputs UTF-8 (per spec)- Streaming helper interfaces like
TextDecoderStreamare not exposed; use repeateddecode()calls with{stream: true}insteadfatal: trueis set, the decoder throws aTypeErroron the first invalid byte sequenceMust do before going out of draft
Checklist
make check) and all pass.Related PR(s)/Issue(s)
closes #2440