ZipFile and BytesIO in Python3 to K6

Getting started with K6 was easy. But, now facing some difficulties porting Python code to K6.

Python code - START

# Imports
import base64
from zipfile import ZipFile
from io import BytesIO

# Extract Zip
def extract_zip(self, input_zip):
    input_zip = ZipFile(BytesIO(input_zip))
    for name in input_zip.namelist():
        if name.endswith(".json"):

# Code snippet
base64_data = USER_INPUT_DATA
data_b4_utf8_decode = self.extract_zip(base64.b64decode(base64_data))
data = data_b4_utf8_decode.decode('utf-8')

Python code - END

Above is a snippet of Python code. I was able to get the K6 equivalent for b64decode (encoding.b64decode()). But, how will the rest of the code be realized in K6?


Hi @melvin,
welcome to the community forum :tada: and sorry for the late response. :pray:

k6 doesn’t support directly zip files so I can just offer some alternatives:

  • Create an xk6 extension so you could benefit from the available Go libraries for extracting your files.
  • Import available js modules, in this case, I can’t guarantee that it will work because it mostly depends on the compatibility between the picked libraries and k6 as described in the guide.