Question

Binary String to Zip File in Memory


Badge +1

Is it possible to take a binary string in memory and use it in a transformer to tell it to treat it as a zip file? I know I can use a FeatureWriter (format set to data file) to write the binary string to disk then use a FeatureReader to read it back into memory. I was trying to skip the step of writing it to disk. Any help would be great!


2 replies

Userlevel 4
Badge +13

Hi @justincornell Is performance your main concern? I think it would be easiest to make a RAM disk and write your zip file to that.

Userlevel 2
Badge +17

Hi @justincornell, if the binary data containing zipped archives is saved as a feature attribute, you can manipulate it as a zip file directly with a Python, PythonCaller. e.g.

# PythonCaller Script Example
# Assuming the attribute "_response_body" stores
# a binary data containing zipped archives.
import fme, fmeobjects
import io, zipfile
class ZipManipulator(object):
    def __init__(self):
        pass
        
    def input(self, feature):
        bin = feature.getAttribute('_response_body')
        buff = io.BytesIO(bin)
        with zipfile.ZipFile(buff, 'r') as z:
            #
            # Do something with the ZipFile object.
            #
            pass

Reply