Blob Blame History Raw
From: "Matwey V. Kornilov" <matwey.kornilov@gmail.com>
Date: Sun, 18 Mar 2018 16:41:41 +0300
Subject: [PATCH] Add AtU8 beam file chunk decoding support

AtU8 is the same as Atom excepting strings are UTF-8 encoded.

http://beam-wisdoms.clau.se/en/latest/indepth-beam-file.html#atom-and-atu8-atoms-table

Fix #7

diff --git a/pybeam/beam_construct.py b/pybeam/beam_construct.py
index b930e61..d7c74e3 100644
--- a/pybeam/beam_construct.py
+++ b/pybeam/beam_construct.py
@@ -29,6 +29,8 @@ erl_version_magic = Magic(b'\x83')
 
 chunk_atom = Rename("chunk_atom", PrefixedArray(PascalString("atom", encoding="latin1"), length_field = UBInt32("len")))
 
+chunk_atu8 = Rename("chunk_atu8", PrefixedArray(PascalString("atu8", encoding="utf8"), length_field = UBInt32("len")))
+
 chunk_attr = Rename("chunk_attr", external_term)
 
 chunk_cinf = Rename("chunk_cinf", external_term)
@@ -105,6 +107,7 @@ chunk = Struct("chunk",
 				{
 #				"Abst" : chunk_abst,
 				b"Atom" : chunk_atom,
+				b"AtU8" : chunk_atu8,
 				b"Attr" : chunk_attr,
 				b"CInf" : chunk_cinf,
 				b"Code" : chunk_code,
diff --git a/pybeam/beam_file.py b/pybeam/beam_file.py
index ef2203d..0b8bed5 100644
--- a/pybeam/beam_file.py
+++ b/pybeam/beam_file.py
@@ -34,6 +34,10 @@ class BeamFile(object):
 
 	@property
 	def atoms(self):
+		try:
+			return self.selectChunkByName(b"AtU8").payload
+		except KeyError:
+			pass
 		return self.selectChunkByName(b"Atom").payload
 
 	@property