Skip to content

Commit

Permalink
Use raw_unicode_escape instead of base64 encoding
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
psavery committed Nov 24, 2023
1 parent 988e5cc commit 8a9cee7
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hexrd/utils/json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
import io
import json

Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 8a9cee7

Please sign in to comment.