[gnome-maps/wip/mlundblad/es6-modules: 8/19] scripts/extractPoiTypesFromID: Stop using imports.byteArray




commit 94948ea794e026c6496a6e168056915c3545c4c6
Author: Marcus Lundblad <ml dfupdate se>
Date:   Mon May 23 23:34:43 2022 +0200

    scripts/extractPoiTypesFromID: Stop using imports.byteArray
    
    Replace usage with ES TextDecoder.

 scripts/extractPoiTypesFromID.js | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
---
diff --git a/scripts/extractPoiTypesFromID.js b/scripts/extractPoiTypesFromID.js
index 4ef45fb4..32585b17 100755
--- a/scripts/extractPoiTypesFromID.js
+++ b/scripts/extractPoiTypesFromID.js
@@ -31,8 +31,6 @@
 
 import Gio from 'gi://Gio';
 
-const ByteArray = imports.byteArray;
-
 const PRESETS_PATH = 'data/presets';
 const LOCALES_PATH = 'dist/translations';
 const PRESET_TYPES = [ 'aeroway',
@@ -45,18 +43,12 @@ const PRESET_TYPES = [ 'aeroway',
 
 const OUTPUT = {};
 
-function getBufferText(buffer) {
-    if (buffer instanceof Uint8Array) {
-        return ByteArray.toString(buffer);
-    } else {
-        return buffer.toString();
-    }
-}
+let decoder = new TextDecoder('utf-8');
 
 function parseJson(dirPath, fileName) {
     let file = Gio.File.new_for_path(dirPath + '/' + fileName);
     let [status, buffer] = file.load_contents(null);
-    let {tags, name} = JSON.parse(getBufferText(buffer));
+    let {tags, name} = JSON.parse(decoder.decode(buffer));
 
     for (let key in tags) {
         let value = tags[key];
@@ -92,7 +84,7 @@ function processTypes(basePath) {
 function processLocale(dirPath, fileName) {
     let file = Gio.File.new_for_path(dirPath + '/' + fileName);
     let [status, buffer] = file.load_contents(null);
-    let object = JSON.parse(getBufferText(buffer));
+    let object = JSON.parse(decoder.decode(buffer));
     let lang = fileName.substring(0, fileName.indexOf('.json'));
 
     for (let type in OUTPUT) {


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