Skip to content

adding decompression of gzipped files#52

Closed
kkdd wants to merge 1 commit intomakinacorpus:masterfrom
kkdd:patch-1
Closed

adding decompression of gzipped files#52
kkdd wants to merge 1 commit intomakinacorpus:masterfrom
kkdd:patch-1

Conversation

@kkdd
Copy link
Contributor

@kkdd kkdd commented Nov 19, 2017

No description provided.

@leplatrem
Copy link
Collaborator

Nice :)

I think that this is a little bit out of scope for this tiny tool though.

We should use this use-case to introduce the necessary «hooks» to allow to support decompression, as you did, but not merge it with the plugin code.

What do you think ?

@kkdd
Copy link
Contributor Author

kkdd commented Nov 25, 2017

Thank you for your idea.
Would it be better by separating the following function code from leaflet.filelayer.js?

 /*
  * 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
  */

this._decompressors = {
    gz: function (x) {return gzip.decompress(x);}
};

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));
    }
})();

@leplatrem
Copy link
Collaborator

We could add an API to add custom parsers. For example:

gzipParser = {
  extensions: ['.gzip'],
  read: function (fileReader) {
    return fileReader.readAsArrayBuffer()
  },
  toGeoJSONString: function(data) {
    // ... your custom gzip code
  }
}     

L.FileLayer.FileLoader.addParser(gzipParser);

It would require some refactor here and there, but I think it would be beneficial for the existing code too.

What do you think?

@nathanvda
Copy link

Very much in favour of an API to add custom parsers. I would want to add shp/xml/csv parsers but for the moment these all reside in separate plugins with overlapping functionality.

Do you need any help to add that?

@leplatrem
Copy link
Collaborator

Do you need any help to add that?

I don't contribute to this library anymore. But would be glad to review/test if someone submits some code :)

@kkdd
Copy link
Contributor Author

kkdd commented Feb 24, 2018

New PR: #56

@kkdd kkdd closed this Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants