diff pytouhou/utils/helpers.py @ 0:6b2c7af2384c

Hello Gensokyo _o/
author Thibaut Girka <thib@sitedethib.com>
date Sun, 31 Jul 2011 21:32:12 +0200
parents
children ab826bc29aa2
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/pytouhou/utils/helpers.py
@@ -0,0 +1,12 @@
+def read_string(file, size, encoding=None):
+    data = file.read(size)
+
+    try:
+        data = data[:data.index(b'\x00')]
+    except ValueError:
+        pass
+
+    if encoding:
+        return data.decode(encoding)
+    else:
+        return data