From 8a9cee702fd7a9f37a9c17ca1a244e698023dbf0 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Fri, 24 Nov 2023 14:33:13 -0600 Subject: [PATCH] Use raw_unicode_escape instead of base64 encoding We can consider other encodings as well. Just need to get the bytes to a string and back. The raw_unicode_escale appears to work. Signed-off-by: Patrick Avery --- hexrd/utils/json.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hexrd/utils/json.py b/hexrd/utils/json.py index 46a3e9ff9..f56e707f1 100644 --- a/hexrd/utils/json.py +++ b/hexrd/utils/json.py @@ -1,4 +1,3 @@ -import base64 import io import json @@ -27,8 +26,7 @@ def default(self, obj): data = bytes_io.getvalue() return { - # Need to base64 encode it so it is json-valid - ndarray_key: base64.b64encode(data).decode('ascii') + ndarray_key: data.decode('raw_unicode_escape') } return super().default(obj) @@ -44,7 +42,7 @@ def __init__(self, *args, **kwargs): def object_hook(self, obj): if ndarray_key in obj: - data = base64.b64decode(obj[ndarray_key]) + data = obj[ndarray_key].encode('raw_unicode_escape') with io.BytesIO(data) as bytes_io: return np.load(bytes_io)