-
Notifications
You must be signed in to change notification settings - Fork 89
using DECOMPRESSORS when globally defined #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kkdd
wants to merge
4
commits into
makinacorpus:master
Choose a base branch
from
kkdd:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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);} | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this always true? You are assuming that the file will |
||
| } | ||
| } | ||
| parser = this._parsers[ext]; | ||
| if (!parser) { | ||
| this.fire('data:error', { | ||
|
|
@@ -174,6 +192,7 @@ | |
| } | ||
| return { | ||
| processor: parser, | ||
| decompressor: decompressor, | ||
| ext: ext | ||
| }; | ||
| }, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't we include the decompression in the
parser.processorfunction if a decompressor is defined?