[gnome-maps/wip/mlundblad/es6-modules: 13/25] utils: Stop using imports.byteArray




commit 9c6fc6a558be2069043d7e32220b786f66849d34
Author: Marcus Lundblad <ml dfupdate se>
Date:   Mon May 23 23:30:26 2022 +0200

    utils: Stop using imports.byteArray
    
    Replace usage with ES TextDecoder.

 src/utils.js | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 91f88937..2cf6920b 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -34,8 +34,6 @@ import Soup from 'gi://Soup';
 const _ = gettext.gettext;
 const ngettext = gettext.ngettext;
 
-const ByteArray = imports.byteArray;
-
 export const METRIC_SYSTEM = 1;
 export const IMPERIAL_SYSTEM = 2;
 
@@ -465,15 +463,13 @@ export function showDialog(msg, type, transientFor) {
     messageDialog.show_all();
 }
 
+let decoder = new TextDecoder('utf-8');
+
 /* Gets a string from either a ByteArray or Uint8Array. This is for
 compatibility between two different Gjs versions, see discussion at
 https://gitlab.gnome.org/GNOME/gnome-maps/merge_requests/19 */
 export function getBufferText(buffer) {
-    if (buffer instanceof Uint8Array) {
-        return ByteArray.toString(buffer);
-    } else {
-        return buffer.toString();
-    }
+    return decoder.decode(buffer);
 }
 
 export function getCountryCodeForCoordinates(lat, lon) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]