Skip to main content
Question

Binary String to Zip File in Memory

  • May 4, 2018
  • 2 replies
  • 318 views

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!

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

fmelizard
Safer
Forum|alt.badge.img+20
  • Safer
  • 3719 replies
  • 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
Celebrity
  • 7843 replies
  • 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