helper: a function to extract one file from a packed io block
2 files changed, 20 insertions(+), 0 deletions(-)

M rework/helper.py
M tests/test_api.py
M rework/helper.py +16 -0
@@ 506,3 506,19 @@ def unpack_iofiles_length(spec, packedby
 
     return output
 
+
+def unpack_iofile(spec, packedbytes, name):
+    output = _raw_unpack_io(spec, packedbytes)
+
+    for field in spec:
+        fname = field['name']
+        if fname != name:
+            output.pop(fname, None)
+            continue
+
+        assert field['type'] == 'file'
+
+        inp = _iobase.from_type(
+            'file', fname, field['required'], field['choices']
+        )
+        return inp.binary_decode(output)

          
M tests/test_api.py +4 -0
@@ 6,6 6,7 @@ from rework.helper import (
     iospec,
     host,
     unpack_io,
+    unpack_iofile,
     unpack_iofiles_length
 )
 from rework import api, io

          
@@ 318,6 319,9 @@ def test_prepare_with_inputs(engine, cle
         'myfile.txt': 9
     }
 
+    unpacked_file = unpack_iofile(spec, inputdata, 'myfile.txt')
+    assert unpacked_file == b'some file'
+
 
 def test_with_noinput(engine, cleanup):
     reset_ops(engine)