Skip to main content
Question

Binary String to Zip File in Memory


Forum|alt.badge.img+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

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • May 4, 2018

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.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • May 6, 2018

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

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings