From 9a87c38daba4d80cd53c99c4f47af7c5b18a3057 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich <yannick.ulrich@psi.ch> Date: Sun, 16 Feb 2020 11:42:38 +0100 Subject: [PATCH] 1: added write_record in python towards #12 --- pymule/vegas.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pymule/vegas.py b/pymule/vegas.py index ce46ba4..4df798c 100644 --- a/pymule/vegas.py +++ b/pymule/vegas.py @@ -21,6 +21,20 @@ def read_record(fp, typ): return body +def write_record(fp, typ, content): + if type(content) == str and len(content) > 1: + content = list(content) + elif type(content) != list: + content = [content] + + body = "".join( + struct.pack("<"+typ, i) for i in content + ) + fp.write(struct.pack('<I', len(body))) + fp.write(body) + fp.write(struct.pack('<I', len(body))) + + def guess_version(fp, inttype='i'): fp.seek(0) magic = fp.read(17).replace('\00', '') -- GitLab