From 53ad79e5f8efb89fe4d4ee8c647b3c06fb8db3ae Mon Sep 17 00:00:00 2001 From: kkdd Date: Sat, 24 Feb 2018 23:05:26 +0900 Subject: [PATCH 1/4] Create decompressors.js --- src/decompressors.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/decompressors.js diff --git a/src/decompressors.js b/src/decompressors.js new file mode 100644 index 0000000..27fecc7 --- /dev/null +++ b/src/decompressors.js @@ -0,0 +1,26 @@ + + +/* +* Decompression of gzipped files using ukyo's jsziptools.js (jz) +* Requires ukyo's jsziptools.js to be in global scope when decompressing gzipped files +* https://github.com/ukyo/jsziptools +* http://ukyo.github.io/jsziptools/jsziptools.js +*/ +var gzip = (function () { + return { + decompress: function(arrayBuffer) { + var hexarr = jz.gz.decompress(arrayBuffer); + return _hextostring(hexarr); + }, + }; + function _hextostring(hexarr){ + for (var w = '', i = 0, l = hexarr.length; i < l; i++) { + w += String.fromCharCode(hexarr[i]) + } + return decodeURIComponent(escape(w)); + } +})(); + +var DECOMPRESSORS = { + gz: function (x) {return gzip.decompress(x);} +}; From 5a368cb9da418d55943802dbc7cf9f4c9a7f36de Mon Sep 17 00:00:00 2001 From: kkdd Date: Sat, 24 Feb 2018 23:17:33 +0900 Subject: [PATCH 2/4] using decompressors --- src/leaflet.filelayer.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/leaflet.filelayer.js b/src/leaflet.filelayer.js index 19b6ae7..58785b3 100644 --- a/src/leaflet.filelayer.js +++ b/src/leaflet.filelayer.js @@ -56,8 +56,11 @@ gpx: this._convertToGeoJSON, kml: this._convertToGeoJSON }; + + this._decompressors = typeof(DECOMPRESSORS)==='undefined'?{}:DECOMPRESSORS; }, + load: function (file, ext) { var parser, reader; @@ -84,7 +87,11 @@ var layer; try { this.fire('data:loading', { filename: file.name, format: parser.ext }); - layer = parser.processor.call(this, e.target.result, parser.ext); + var result = e.target.result; + if (parser.decompressor) { + result = parser.decompressor(result); + } + layer = parser.processor.call(this, result, parser.ext); this.fire('data:loaded', { layer: layer, filename: file.name, @@ -98,7 +105,11 @@ // but an object with file.testing set to true. // This object cannot be read by reader, just skip it. if (!file.testing) { - reader.readAsText(file); + if (parser.decompressor) { + reader.readAsArrayBuffer(file); + } else { + reader.readAsText(file, 'utf-8'); + } } // We return this to ease testing return reader; @@ -163,8 +174,15 @@ }, _getParser: function (name, ext) { - var parser; - ext = ext || name.split('.').pop(); + var parser, decompressor; + if (!ext) { + name = name.split('.'); + ext = name.pop(); + decompressor = this._decompressors[ext]; + if (decompressor) { + ext = name.pop(); + } + } parser = this._parsers[ext]; if (!parser) { this.fire('data:error', { @@ -174,6 +192,7 @@ } return { processor: parser, + decompressor: decompressor, ext: ext }; }, From 46449835f27eba273aa0d85621f9a6de0954fff1 Mon Sep 17 00:00:00 2001 From: kkdd Date: Sat, 24 Feb 2018 23:18:58 +0900 Subject: [PATCH 3/4] Update leaflet.filelayer.js --- src/leaflet.filelayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leaflet.filelayer.js b/src/leaflet.filelayer.js index 58785b3..a9130a1 100644 --- a/src/leaflet.filelayer.js +++ b/src/leaflet.filelayer.js @@ -57,7 +57,7 @@ kml: this._convertToGeoJSON }; - this._decompressors = typeof(DECOMPRESSORS)==='undefined'?{}:DECOMPRESSORS; + this._decompressors = typeof(DECOMPRESSORS)==='undefined'?{}:DECOMPRESSORS; }, From 39366457b046806d690f83b92e9200466ba17a22 Mon Sep 17 00:00:00 2001 From: kkdd Date: Sat, 24 Feb 2018 23:25:34 +0900 Subject: [PATCH 4/4] Update decompressors.js --- src/decompressors.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/decompressors.js b/src/decompressors.js index 27fecc7..feee49a 100644 --- a/src/decompressors.js +++ b/src/decompressors.js @@ -1,5 +1,3 @@ - - /* * Decompression of gzipped files using ukyo's jsziptools.js (jz) * Requires ukyo's jsziptools.js to be in global scope when decompressing gzipped files