@loaders.gl/tile-converter 3.1.0-alpha.4 → 3.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/converter.js +1 -1
- package/dist/bundle.js +86025 -0
- package/dist/converter.min.js +292 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +189 -421
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +214 -296
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -8
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +7 -17
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +17 -65
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -33
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +93 -103
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +348 -511
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +30 -26
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +102 -203
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +701 -1501
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +15 -25
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +2 -2
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +12 -21
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +3 -5
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +15 -55
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +4 -6
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +20 -60
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +14 -41
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/geoid-height-model.js +100 -114
- package/dist/es5/lib/geoid-height-model.js.map +1 -1
- package/dist/es5/lib/pgm-parser.js +68 -122
- package/dist/es5/lib/pgm-parser.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +123 -345
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +20 -98
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +41 -152
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/pgm-loader.js +3 -5
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +19 -13
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +19 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +29 -31
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +50 -31
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +2 -2
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/store.js +2 -2
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/esm/i3s-server/controllers/index-controller.js +2 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/esm/lib/utils/compress-util.js +13 -13
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +1 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/statistic-utills.js +5 -5
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/package.json +22 -19
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
- package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
- package/src/i3s-converter/helpers/geometry-converter.js +21 -22
- package/src/i3s-converter/i3s-converter.ts +32 -7
- package/src/i3s-converter/json-templates/metadata.js +1 -1
- package/src/i3s-converter/json-templates/scene-server.js +1 -1
- package/src/i3s-converter/json-templates/store.js +2 -2
- package/src/i3s-server/controllers/index-controller.js +1 -1
- package/dist/dist.min.js +0 -94
- package/dist/dist.min.js.map +0 -1
- package/dist/scripts/converter.js +0 -274
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/pgm-parser.js"],"names":["_getLineGenerator","ENDL","PIXEL_MAX","parsePgm","data","options","getline","currentLine","next","done","value","line","Error","_offset","Number","MAX_VALUE","_scale","_maxerror","_rmserror","_description","_datetime","_width","_height","_datastart","_swidth","s","length","sArr","split","commentId","key","infoArr","slice","join","parseInt","parseFloat","cubic","isFinite","filter","testString","maxval","offset","_rlonres","_rlatres","GeoidHeightModel","endLineIndex","indexOf","subarray","_getStringFromCharArray","array","char","String","fromCharCode"],"mappings":";;;;;;;;;;;AAcA;;;;;;;;wCAwIUA,iB;;AAtIV,IAAMC,IAAI,GAAG,EAAb;AACA,IAAMC,SAAS,GAAG,KAAlB;;AAGO,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,OAAxB,EAAiC;AACtC,MAAMC,OAAO,GAAGN,iBAAiB,CAACI,IAAD,CAAjC;;AACA,MAAIG,WAAW,GAAGD,OAAO,CAACE,IAAR,EAAlB;;AACA,MAAID,WAAW,CAACE,IAAZ,IAAoBF,WAAW,CAACG,KAAZ,CAAkBC,IAAlB,KAA2B,IAAnD,EAAy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,WAAN;;AAPN;AAAA;AAAA;;AAAA;AASYA,UAAAA,KATZ,GASmBP,IAAI,CAAC2C,QAAL,CAAcN,MAAd,EAAsBrC,IAAI,CAACsB,MAA3B,CATnB;AAUMe,UAAAA,MAAM,GAAGrC,IAAI,CAACsB,MAAd;AAVN;AAWM,iBAAM;AAACe,YAAAA,MAAM,EAANA,MAAD;AAAS9B,YAAAA,IAAI,EAAEqC,uBAAuB,CAACrC,KAAD;AAAtC,WAAN;;AAXN;AAAA,cAaW8B,MAAM,GAAGrC,IAAI,CAACsB,MAbzB;AAAA;AAAA;AAAA;;AAAA;AAAA,2CAcS;AAACe,YAAAA,MAAM,EAANA,MAAD;AAAS9B,YAAAA,IAAI,EAAE;AAAf,WAdT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAsBA,SAASqC,uBAAT,CAAiCC,KAAjC,EAAwC;AACtC,MAAIxB,CAAC,GAAG,EAAR;;AADsC,6CAEnBwB,KAFmB;AAAA;;AAAA;AAEtC,wDAA0B;AAAA,UAAfC,IAAe;AACxBzB,MAAAA,CAAC,IAAI0B,MAAM,CAACC,YAAP,CAAoBF,IAApB,CAAL;AACD;AAJqC;AAAA;AAAA;AAAA;AAAA;;AAKtC,SAAOzB,CAAP;AACD","sourcesContent":["/**\n * Parsing code is ported from GeographicLib-1.50.1\n * https://geographiclib.sourceforge.io/html/index.html\n * Location: /GeographicLib-1.50.1/src/Geoid.cpp\n *\n * File header:\n * * \\file Geoid.cpp\n * * \\brief Implementation for GeographicLib::Geoid class\n * *\n * * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed\n * * under the MIT/X11 License. For more information, see\n * * https://geographiclib.sourceforge.io/\n **********************************************************************/\n\nimport {GeoidHeightModel} from './geoid-height-model';\n\nconst ENDL = 10;\nconst PIXEL_MAX = 65535;\n\n// eslint-disable-next-line\nexport function parsePgm(data, options) {\n const getline = _getLineGenerator(data);\n let currentLine = getline.next();\n if (currentLine.done || currentLine.value.line !== 'P5') {\n throw new Error('Geoid model file: File not in PGM format');\n }\n let _offset = Number.MAX_VALUE;\n let _scale = 0;\n let _maxerror = -1;\n let _rmserror = -1;\n let _description = 'NONE';\n let _datetime = 'UNKNOWN';\n let _width = 0;\n let _height = 0;\n let _datastart = null;\n let _swidth = null;\n do {\n currentLine = getline.next();\n const s = currentLine.value.line;\n if (!s.length) {\n continue; // eslint-disable-line no-continue\n }\n if (s[0] === '#') {\n const sArr = s.split(' ');\n const commentId = sArr[0];\n const key = sArr[1];\n if (commentId !== '#' || !key) {\n continue; // eslint-disable-line no-continue\n }\n const infoArr = sArr.length > 2 ? sArr.slice(2) : [];\n if (key === 'Description') {\n _description = infoArr.join(' ');\n } else if (key === 'DateTime') {\n _datetime = infoArr.join(' ');\n } else if (key === 'Offset') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading offset');\n }\n _offset = parseInt(sArr[2], 10);\n } else if (key === 'Scale') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading scale');\n }\n _scale = parseFloat(sArr[2]);\n } else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _maxerror = parseFloat(sArr[2]);\n }\n } else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _rmserror = parseFloat(sArr[2]);\n }\n }\n } else {\n let sArr = s.split(' ');\n sArr = sArr.filter((testString) => testString !== '');\n _width = parseInt(sArr[0], 10);\n _height = parseInt(sArr[1], 10);\n if (!(_width && _height)) {\n throw new Error('Geoid model file: Error reading raster size');\n }\n break;\n }\n } while (!currentLine.done);\n\n currentLine = getline.next();\n const maxval = parseInt(currentLine.value.line, 10);\n if (currentLine.done) {\n throw new Error('Geoid model file: Error reading maxval');\n }\n if (maxval !== PIXEL_MAX) {\n throw new Error('Geoid model file: Incorrect value of maxval');\n }\n // Add 1 for whitespace after maxval\n _datastart = currentLine.value.offset;\n _swidth = _width;\n\n if (_offset === Number.MAX_VALUE) {\n throw new Error('Geoid model file: Offset not set');\n }\n if (_scale === 0) {\n throw new Error('Geoid model file: Scale not set');\n }\n if (_scale < 0) {\n throw new Error('Geoid model file: Scale must be positive');\n }\n if (_height < 2 || _width < 2) {\n // Coarsest grid spacing is 180deg.\n throw new Error('Geoid model file: Raster size too small');\n }\n if (_width & 1) {\n // This is so that longitude grids can be extended thru the poles.\n throw new Error('Geoid model file: Raster width is odd');\n }\n if (!(_height & 1)) {\n // This is so that latitude grid includes the equator.\n throw new Error('Geoid model file: Raster height is even');\n }\n\n const _rlonres = _width / 360;\n const _rlatres = (_height - 1) / 180;\n return new GeoidHeightModel({\n cubic: options.cubic,\n _width,\n _height,\n _rlonres,\n _rlatres,\n _offset,\n _scale,\n _swidth,\n _datastart,\n _maxerror,\n _rmserror,\n _description,\n _datetime,\n data\n });\n}\n\n/**\n * Yields strings from pgm file (splitted by 10 - new line symbol)\n * @param {Uint8Array} data - binary buffer of pgm file\n * @returns {Generator}\n */\nfunction* _getLineGenerator(data) {\n let offset = 0;\n do {\n const endLineIndex = data.indexOf(ENDL, offset);\n if (endLineIndex !== -1) {\n const line = data.subarray(offset, endLineIndex);\n offset = endLineIndex + 1;\n yield {offset, line: _getStringFromCharArray(line)};\n } else {\n const line = data.subarray(offset, data.length);\n offset = data.length;\n yield {offset, line: _getStringFromCharArray(line)};\n }\n } while (offset < data.length);\n return {offset, line: ''};\n}\n\n/**\n * Converts Uint8Array of char-codes to string\n * @param {Uint8Array} array - binary buffer of pgm file\n * @returns {string}\n */\nfunction _getStringFromCharArray(array) {\n let s = '';\n for (const char of array) {\n s += String.fromCharCode(char);\n }\n return s;\n}\n"],"file":"pgm-parser.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/pgm-parser.js"],"names":["ENDL","PIXEL_MAX","parsePgm","data","options","getline","_getLineGenerator","currentLine","next","done","value","line","Error","_offset","Number","MAX_VALUE","_scale","_maxerror","_rmserror","_description","_datetime","_width","_height","_datastart","_swidth","s","length","sArr","split","commentId","key","infoArr","slice","join","parseInt","parseFloat","cubic","isFinite","filter","testString","maxval","offset","_rlonres","_rlatres","GeoidHeightModel","endLineIndex","indexOf","subarray","_getStringFromCharArray","array","char","String","fromCharCode"],"mappings":";;;;;;;AAcA;;AAEA,MAAMA,IAAI,GAAG,EAAb;AACA,MAAMC,SAAS,GAAG,KAAlB;;AAGO,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,OAAxB,EAAiC;AACtC,QAAMC,OAAO,GAAGC,iBAAiB,CAACH,IAAD,CAAjC;;AACA,MAAII,WAAW,GAAGF,OAAO,CAACG,IAAR,EAAlB;;AACA,MAAID,WAAW,CAACE,IAAZ,IAAoBF,WAAW,CAACG,KAAZ,CAAkBC,IAAlB,KAA2B,IAAnD,EAAyD;AACvD,UAAM,IAAIC,KAAJ,CAAU,0CAAV,CAAN;AACD;;AACD,MAAIC,OAAO,GAAGC,MAAM,CAACC,SAArB;AACA,MAAIC,MAAM,GAAG,CAAb;;AACA,MAAIC,SAAS,GAAG,CAAC,CAAjB;;AACA,MAAIC,SAAS,GAAG,CAAC,CAAjB;;AACA,MAAIC,YAAY,GAAG,MAAnB;AACA,MAAIC,SAAS,GAAG,SAAhB;AACA,MAAIC,MAAM,GAAG,CAAb;AACA,MAAIC,OAAO,GAAG,CAAd;AACA,MAAIC,UAAU,GAAG,IAAjB;AACA,MAAIC,OAAO,GAAG,IAAd;;AACA,KAAG;AACDjB,IAAAA,WAAW,GAAGF,OAAO,CAACG,IAAR,EAAd;AACA,UAAMiB,CAAC,GAAGlB,WAAW,CAACG,KAAZ,CAAkBC,IAA5B;;AACA,QAAI,CAACc,CAAC,CAACC,MAAP,EAAe;AACb;AACD;;AACD,QAAID,CAAC,CAAC,CAAD,CAAD,KAAS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,CAAb;;AACA,KAAG;AACD,UAAMI,YAAY,GAAG1C,IAAI,CAAC2C,OAAL,CAAa9C,IAAb,EAAmByC,MAAnB,CAArB;;AACA,QAAII,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvB,YAAMlC,IAAI,GAAGR,IAAI,CAAC4C,QAAL,CAAcN,MAAd,EAAsBI,YAAtB,CAAb;AACAJ,MAAAA,MAAM,GAAGI,YAAY,GAAG,CAAxB;AACA,YAAM;AAACJ,QAAAA,MAAD;AAAS9B,QAAAA,IAAI,EAAEqC,uBAAuB,CAACrC,IAAD;AAAtC,OAAN;AACD,KAJD,MAIO;AACL,YAAMA,IAAI,GAAGR,IAAI,CAAC4C,QAAL,CAAcN,MAAd,EAAsBtC,IAAI,CAACuB,MAA3B,CAAb;AACAe,MAAAA,MAAM,GAAGtC,IAAI,CAACuB,MAAd;AACA,YAAM;AAACe,QAAAA,MAAD;AAAS9B,QAAAA,IAAI,EAAEqC,uBAAuB,CAACrC,IAAD;AAAtC,OAAN;AACD;AACF,GAXD,QAWS8B,MAAM,GAAGtC,IAAI,CAACuB,MAXvB;;AAYA,SAAO;AAACe,IAAAA,MAAD;AAAS9B,IAAAA,IAAI,EAAE;AAAf,GAAP;AACD;;AAOD,SAASqC,uBAAT,CAAiCC,KAAjC,EAAwC;AACtC,MAAIxB,CAAC,GAAG,EAAR;;AACA,OAAK,MAAMyB,IAAX,IAAmBD,KAAnB,EAA0B;AACxBxB,IAAAA,CAAC,IAAI0B,MAAM,CAACC,YAAP,CAAoBF,IAApB,CAAL;AACD;;AACD,SAAOzB,CAAP;AACD","sourcesContent":["/**\n * Parsing code is ported from GeographicLib-1.50.1\n * https://geographiclib.sourceforge.io/html/index.html\n * Location: /GeographicLib-1.50.1/src/Geoid.cpp\n *\n * File header:\n * * \\file Geoid.cpp\n * * \\brief Implementation for GeographicLib::Geoid class\n * *\n * * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed\n * * under the MIT/X11 License. For more information, see\n * * https://geographiclib.sourceforge.io/\n **********************************************************************/\n\nimport {GeoidHeightModel} from './geoid-height-model';\n\nconst ENDL = 10;\nconst PIXEL_MAX = 65535;\n\n// eslint-disable-next-line\nexport function parsePgm(data, options) {\n const getline = _getLineGenerator(data);\n let currentLine = getline.next();\n if (currentLine.done || currentLine.value.line !== 'P5') {\n throw new Error('Geoid model file: File not in PGM format');\n }\n let _offset = Number.MAX_VALUE;\n let _scale = 0;\n let _maxerror = -1;\n let _rmserror = -1;\n let _description = 'NONE';\n let _datetime = 'UNKNOWN';\n let _width = 0;\n let _height = 0;\n let _datastart = null;\n let _swidth = null;\n do {\n currentLine = getline.next();\n const s = currentLine.value.line;\n if (!s.length) {\n continue; // eslint-disable-line no-continue\n }\n if (s[0] === '#') {\n const sArr = s.split(' ');\n const commentId = sArr[0];\n const key = sArr[1];\n if (commentId !== '#' || !key) {\n continue; // eslint-disable-line no-continue\n }\n const infoArr = sArr.length > 2 ? sArr.slice(2) : [];\n if (key === 'Description') {\n _description = infoArr.join(' ');\n } else if (key === 'DateTime') {\n _datetime = infoArr.join(' ');\n } else if (key === 'Offset') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading offset');\n }\n _offset = parseInt(sArr[2], 10);\n } else if (key === 'Scale') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading scale');\n }\n _scale = parseFloat(sArr[2]);\n } else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _maxerror = parseFloat(sArr[2]);\n }\n } else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _rmserror = parseFloat(sArr[2]);\n }\n }\n } else {\n let sArr = s.split(' ');\n sArr = sArr.filter((testString) => testString !== '');\n _width = parseInt(sArr[0], 10);\n _height = parseInt(sArr[1], 10);\n if (!(_width && _height)) {\n throw new Error('Geoid model file: Error reading raster size');\n }\n break;\n }\n } while (!currentLine.done);\n\n currentLine = getline.next();\n const maxval = parseInt(currentLine.value.line, 10);\n if (currentLine.done) {\n throw new Error('Geoid model file: Error reading maxval');\n }\n if (maxval !== PIXEL_MAX) {\n throw new Error('Geoid model file: Incorrect value of maxval');\n }\n // Add 1 for whitespace after maxval\n _datastart = currentLine.value.offset;\n _swidth = _width;\n\n if (_offset === Number.MAX_VALUE) {\n throw new Error('Geoid model file: Offset not set');\n }\n if (_scale === 0) {\n throw new Error('Geoid model file: Scale not set');\n }\n if (_scale < 0) {\n throw new Error('Geoid model file: Scale must be positive');\n }\n if (_height < 2 || _width < 2) {\n // Coarsest grid spacing is 180deg.\n throw new Error('Geoid model file: Raster size too small');\n }\n if (_width & 1) {\n // This is so that longitude grids can be extended thru the poles.\n throw new Error('Geoid model file: Raster width is odd');\n }\n if (!(_height & 1)) {\n // This is so that latitude grid includes the equator.\n throw new Error('Geoid model file: Raster height is even');\n }\n\n const _rlonres = _width / 360;\n const _rlatres = (_height - 1) / 180;\n return new GeoidHeightModel({\n cubic: options.cubic,\n _width,\n _height,\n _rlonres,\n _rlatres,\n _offset,\n _scale,\n _swidth,\n _datastart,\n _maxerror,\n _rmserror,\n _description,\n _datetime,\n data\n });\n}\n\n/**\n * Yields strings from pgm file (splitted by 10 - new line symbol)\n * @param {Uint8Array} data - binary buffer of pgm file\n * @returns {Generator}\n */\nfunction* _getLineGenerator(data) {\n let offset = 0;\n do {\n const endLineIndex = data.indexOf(ENDL, offset);\n if (endLineIndex !== -1) {\n const line = data.subarray(offset, endLineIndex);\n offset = endLineIndex + 1;\n yield {offset, line: _getStringFromCharArray(line)};\n } else {\n const line = data.subarray(offset, data.length);\n offset = data.length;\n yield {offset, line: _getStringFromCharArray(line)};\n }\n } while (offset < data.length);\n return {offset, line: ''};\n}\n\n/**\n * Converts Uint8Array of char-codes to string\n * @param {Uint8Array} array - binary buffer of pgm file\n * @returns {string}\n */\nfunction _getStringFromCharArray(array) {\n let s = '';\n for (const char of array) {\n s += String.fromCharCode(char);\n }\n return s;\n}\n"],"file":"pgm-parser.js"}
|
|
@@ -11,10 +11,6 @@ exports.compressWithChildProcess = compressWithChildProcess;
|
|
|
11
11
|
exports.generateHash128FromZip = generateHash128FromZip;
|
|
12
12
|
exports.addFileToZip = addFileToZip;
|
|
13
13
|
|
|
14
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
15
|
-
|
|
16
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
-
|
|
18
14
|
var _zlib = require("zlib");
|
|
19
15
|
|
|
20
16
|
var _path = require("path");
|
|
@@ -34,16 +30,16 @@ var _crypto = require("@loaders.gl/crypto");
|
|
|
34
30
|
var _crypt = _interopRequireDefault(require("crypt"));
|
|
35
31
|
|
|
36
32
|
function compressFileWithGzip(pathFile) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return new Promise(
|
|
42
|
-
input.on('end',
|
|
33
|
+
const compressedPathFile = "".concat(pathFile, ".gz");
|
|
34
|
+
const gzip = (0, _zlib.createGzip)();
|
|
35
|
+
const input = (0, _fs.createReadStream)(pathFile);
|
|
36
|
+
const output = (0, _fs.createWriteStream)(compressedPathFile);
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
input.on('end', () => {
|
|
43
39
|
console.log("".concat(compressedPathFile, " compressed and saved."));
|
|
44
40
|
resolve(compressedPathFile);
|
|
45
41
|
});
|
|
46
|
-
input.on('error',
|
|
42
|
+
input.on('error', error => {
|
|
47
43
|
console.log("".concat(compressedPathFile, ": compression error!"));
|
|
48
44
|
reject(error);
|
|
49
45
|
});
|
|
@@ -51,368 +47,150 @@ function compressFileWithGzip(pathFile) {
|
|
|
51
47
|
});
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
function compressFilesWithZip(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function _compressFilesWithZip() {
|
|
59
|
-
_compressFilesWithZip = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(fileMap, outputFile) {
|
|
60
|
-
var level,
|
|
61
|
-
output,
|
|
62
|
-
archive,
|
|
63
|
-
_args2 = arguments;
|
|
64
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
65
|
-
while (1) {
|
|
66
|
-
switch (_context2.prev = _context2.next) {
|
|
67
|
-
case 0:
|
|
68
|
-
level = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 0;
|
|
69
|
-
_context2.prev = 1;
|
|
70
|
-
_context2.next = 4;
|
|
71
|
-
return (0, _fileUtils.removeFile)(outputFile);
|
|
72
|
-
|
|
73
|
-
case 4:
|
|
74
|
-
_context2.next = 8;
|
|
75
|
-
break;
|
|
76
|
-
|
|
77
|
-
case 6:
|
|
78
|
-
_context2.prev = 6;
|
|
79
|
-
_context2.t0 = _context2["catch"](1);
|
|
80
|
-
|
|
81
|
-
case 8:
|
|
82
|
-
output = (0, _fs.createWriteStream)(outputFile);
|
|
83
|
-
archive = (0, _archiver.default)('zip', {
|
|
84
|
-
zlib: {
|
|
85
|
-
level: level
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return _context2.abrupt("return", new Promise(function () {
|
|
89
|
-
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(resolve, reject) {
|
|
90
|
-
var subFileName, subFileData;
|
|
91
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
92
|
-
while (1) {
|
|
93
|
-
switch (_context.prev = _context.next) {
|
|
94
|
-
case 0:
|
|
95
|
-
output.on('close', function () {
|
|
96
|
-
console.log("".concat(outputFile, " saved."));
|
|
97
|
-
console.log("".concat(archive.pointer(), " total bytes"));
|
|
98
|
-
resolve(null);
|
|
99
|
-
});
|
|
100
|
-
output.on('end', function () {
|
|
101
|
-
console.log('Data has been drained');
|
|
102
|
-
resolve(null);
|
|
103
|
-
});
|
|
104
|
-
archive.on('warning', function (err) {
|
|
105
|
-
console.log(err);
|
|
106
|
-
reject(err);
|
|
107
|
-
});
|
|
108
|
-
archive.on('error', function (err) {
|
|
109
|
-
reject(err);
|
|
110
|
-
});
|
|
111
|
-
archive.pipe(output);
|
|
112
|
-
_context.t0 = _regenerator.default.keys(fileMap);
|
|
113
|
-
|
|
114
|
-
case 6:
|
|
115
|
-
if ((_context.t1 = _context.t0()).done) {
|
|
116
|
-
_context.next = 13;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
subFileName = _context.t1.value;
|
|
121
|
-
subFileData = fileMap[subFileName];
|
|
122
|
-
_context.next = 11;
|
|
123
|
-
return appendFileToArchive(archive, subFileName, subFileData);
|
|
124
|
-
|
|
125
|
-
case 11:
|
|
126
|
-
_context.next = 6;
|
|
127
|
-
break;
|
|
128
|
-
|
|
129
|
-
case 13:
|
|
130
|
-
archive.finalize();
|
|
131
|
-
|
|
132
|
-
case 14:
|
|
133
|
-
case "end":
|
|
134
|
-
return _context.stop();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}, _callee);
|
|
138
|
-
}));
|
|
139
|
-
|
|
140
|
-
return function (_x13, _x14) {
|
|
141
|
-
return _ref.apply(this, arguments);
|
|
142
|
-
};
|
|
143
|
-
}()));
|
|
144
|
-
|
|
145
|
-
case 11:
|
|
146
|
-
case "end":
|
|
147
|
-
return _context2.stop();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}, _callee2, null, [[1, 6]]);
|
|
151
|
-
}));
|
|
152
|
-
return _compressFilesWithZip.apply(this, arguments);
|
|
153
|
-
}
|
|
50
|
+
async function compressFilesWithZip(fileMap, outputFile, level = 0) {
|
|
51
|
+
try {
|
|
52
|
+
await (0, _fileUtils.removeFile)(outputFile);
|
|
53
|
+
} catch (e) {}
|
|
154
54
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_context3.next = 7;
|
|
180
|
-
return compressWithChildProcessUnix.apply(void 0, _args3);
|
|
181
|
-
|
|
182
|
-
case 7:
|
|
183
|
-
case "end":
|
|
184
|
-
return _context3.stop();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}, _callee3);
|
|
188
|
-
}));
|
|
189
|
-
return _compressWithChildProcess.apply(this, arguments);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function compressWithChildProcessUnix(_x3, _x4) {
|
|
193
|
-
return _compressWithChildProcessUnix.apply(this, arguments);
|
|
194
|
-
}
|
|
55
|
+
const output = (0, _fs.createWriteStream)(outputFile);
|
|
56
|
+
const archive = (0, _archiver.default)('zip', {
|
|
57
|
+
zlib: {
|
|
58
|
+
level
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return new Promise(async (resolve, reject) => {
|
|
62
|
+
output.on('close', function () {
|
|
63
|
+
console.log("".concat(outputFile, " saved."));
|
|
64
|
+
console.log("".concat(archive.pointer(), " total bytes"));
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
output.on('end', function () {
|
|
68
|
+
console.log('Data has been drained');
|
|
69
|
+
resolve(null);
|
|
70
|
+
});
|
|
71
|
+
archive.on('warning', function (err) {
|
|
72
|
+
console.log(err);
|
|
73
|
+
reject(err);
|
|
74
|
+
});
|
|
75
|
+
archive.on('error', function (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
});
|
|
78
|
+
archive.pipe(output);
|
|
195
79
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
fullOutputFile,
|
|
201
|
-
args,
|
|
202
|
-
childProcess,
|
|
203
|
-
_args4 = arguments;
|
|
204
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
205
|
-
while (1) {
|
|
206
|
-
switch (_context4.prev = _context4.next) {
|
|
207
|
-
case 0:
|
|
208
|
-
level = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 0;
|
|
209
|
-
inputFiles = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : '.';
|
|
210
|
-
fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
211
|
-
args = ["-".concat(level), '-r', fullOutputFile, inputFiles];
|
|
212
|
-
childProcess = new _workerUtils.ChildProcessProxy();
|
|
213
|
-
_context4.next = 7;
|
|
214
|
-
return childProcess.start({
|
|
215
|
-
command: 'zip',
|
|
216
|
-
arguments: args,
|
|
217
|
-
spawn: {
|
|
218
|
-
cwd: inputFolder
|
|
219
|
-
},
|
|
220
|
-
wait: 0
|
|
221
|
-
});
|
|
80
|
+
for (const subFileName in fileMap) {
|
|
81
|
+
const subFileData = fileMap[subFileName];
|
|
82
|
+
await appendFileToArchive(archive, subFileName, subFileData);
|
|
83
|
+
}
|
|
222
84
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return _context4.stop();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}, _callee4);
|
|
229
|
-
}));
|
|
230
|
-
return _compressWithChildProcessUnix.apply(this, arguments);
|
|
85
|
+
archive.finalize();
|
|
86
|
+
});
|
|
231
87
|
}
|
|
232
88
|
|
|
233
|
-
function
|
|
234
|
-
|
|
89
|
+
async function compressWithChildProcess() {
|
|
90
|
+
if (process.platform === 'win32') {
|
|
91
|
+
await compressWithChildProcessWindows(...arguments);
|
|
92
|
+
} else {
|
|
93
|
+
await compressWithChildProcessUnix(...arguments);
|
|
94
|
+
}
|
|
235
95
|
}
|
|
236
96
|
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
case 0:
|
|
250
|
-
level = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 0;
|
|
251
|
-
inputFiles = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : (0, _path.join)('.', '*');
|
|
252
|
-
sevenZipExe = _args5.length > 4 ? _args5[4] : undefined;
|
|
253
|
-
|
|
254
|
-
if (inputFiles[0] === '@') {
|
|
255
|
-
inputFiles = "*".concat(inputFiles.substr(1));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
259
|
-
args = ['a', '-tzip', "-mx=".concat(level), fullOutputFile, inputFiles];
|
|
260
|
-
childProcess = new _workerUtils.ChildProcessProxy();
|
|
261
|
-
_context5.next = 9;
|
|
262
|
-
return childProcess.start({
|
|
263
|
-
command: sevenZipExe,
|
|
264
|
-
arguments: args,
|
|
265
|
-
spawn: {
|
|
266
|
-
cwd: "".concat(inputFolder)
|
|
267
|
-
},
|
|
268
|
-
wait: 0
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
case 9:
|
|
272
|
-
case "end":
|
|
273
|
-
return _context5.stop();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}, _callee5);
|
|
277
|
-
}));
|
|
278
|
-
return _compressWithChildProcessWindows.apply(this, arguments);
|
|
97
|
+
async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {
|
|
98
|
+
const fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
99
|
+
const args = ["-".concat(level), '-r', fullOutputFile, inputFiles];
|
|
100
|
+
const childProcess = new _workerUtils.ChildProcessProxy();
|
|
101
|
+
await childProcess.start({
|
|
102
|
+
command: 'zip',
|
|
103
|
+
arguments: args,
|
|
104
|
+
spawn: {
|
|
105
|
+
cwd: inputFolder
|
|
106
|
+
},
|
|
107
|
+
wait: 0
|
|
108
|
+
});
|
|
279
109
|
}
|
|
280
110
|
|
|
281
|
-
function
|
|
282
|
-
|
|
111
|
+
async function compressWithChildProcessWindows(inputFolder, outputFile, level = 0, inputFiles = (0, _path.join)('.', '*'), sevenZipExe) {
|
|
112
|
+
if (inputFiles[0] === '@') {
|
|
113
|
+
inputFiles = "*".concat(inputFiles.substr(1));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
117
|
+
const args = ['a', '-tzip', "-mx=".concat(level), fullOutputFile, inputFiles];
|
|
118
|
+
const childProcess = new _workerUtils.ChildProcessProxy();
|
|
119
|
+
await childProcess.start({
|
|
120
|
+
command: sevenZipExe,
|
|
121
|
+
arguments: args,
|
|
122
|
+
spawn: {
|
|
123
|
+
cwd: "".concat(inputFolder)
|
|
124
|
+
},
|
|
125
|
+
wait: 0
|
|
126
|
+
});
|
|
283
127
|
}
|
|
284
128
|
|
|
285
|
-
function
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
zip = _context6.sent;
|
|
303
|
-
hashTable = [];
|
|
304
|
-
zipFiles = zip.files;
|
|
305
|
-
_context6.t0 = _regenerator.default.keys(zipFiles);
|
|
306
|
-
|
|
307
|
-
case 9:
|
|
308
|
-
if ((_context6.t1 = _context6.t0()).done) {
|
|
309
|
-
_context6.next = 22;
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
relativePath = _context6.t1.value;
|
|
314
|
-
zipEntry = zipFiles[relativePath];
|
|
315
|
-
_data = '_data';
|
|
316
|
-
content = zipEntry[_data].compressedContent;
|
|
317
|
-
|
|
318
|
-
if (!zipEntry.dir) {
|
|
319
|
-
_context6.next = 16;
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return _context6.abrupt("continue", 9);
|
|
324
|
-
|
|
325
|
-
case 16:
|
|
326
|
-
_context6.next = 18;
|
|
327
|
-
return new _crypto.MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));
|
|
328
|
-
|
|
329
|
-
case 18:
|
|
330
|
-
hash = _context6.sent;
|
|
331
|
-
hashTable.push({
|
|
332
|
-
key: atob(hash),
|
|
333
|
-
value: content.byteOffset
|
|
334
|
-
});
|
|
335
|
-
_context6.next = 9;
|
|
336
|
-
break;
|
|
337
|
-
|
|
338
|
-
case 22:
|
|
339
|
-
hashTable.sort(function (prev, next) {
|
|
340
|
-
if (prev.key === next.key) {
|
|
341
|
-
return prev.value < next.value ? -1 : 1;
|
|
342
|
-
}
|
|
129
|
+
async function generateHash128FromZip(inputZipFile, outputFile) {
|
|
130
|
+
const input = await _fs.promises.readFile(inputZipFile);
|
|
131
|
+
const zip = await _jszip.default.loadAsync(input);
|
|
132
|
+
const hashTable = [];
|
|
133
|
+
const zipFiles = zip.files;
|
|
134
|
+
|
|
135
|
+
for (const relativePath in zipFiles) {
|
|
136
|
+
const zipEntry = zipFiles[relativePath];
|
|
137
|
+
const _data = '_data';
|
|
138
|
+
const content = zipEntry[_data].compressedContent;
|
|
139
|
+
if (zipEntry.dir) continue;
|
|
140
|
+
const hash = await new _crypto.MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));
|
|
141
|
+
hashTable.push({
|
|
142
|
+
key: atob(hash),
|
|
143
|
+
value: content.byteOffset
|
|
144
|
+
});
|
|
145
|
+
}
|
|
343
146
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
output.on('close', function () {
|
|
349
|
-
console.log("".concat(outputFile, " generated and saved"));
|
|
350
|
-
resolve(null);
|
|
351
|
-
});
|
|
352
|
-
output.on('error', function (err) {
|
|
353
|
-
console.log(err);
|
|
354
|
-
reject(err);
|
|
355
|
-
});
|
|
147
|
+
hashTable.sort((prev, next) => {
|
|
148
|
+
if (prev.key === next.key) {
|
|
149
|
+
return prev.value < next.value ? -1 : 1;
|
|
150
|
+
}
|
|
356
151
|
|
|
357
|
-
|
|
358
|
-
|
|
152
|
+
return prev.key < next.key ? -1 : 1;
|
|
153
|
+
});
|
|
154
|
+
const output = (0, _fs.createWriteStream)(outputFile);
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
output.on('close', function () {
|
|
157
|
+
console.log("".concat(outputFile, " generated and saved"));
|
|
158
|
+
resolve(null);
|
|
159
|
+
});
|
|
160
|
+
output.on('error', function (err) {
|
|
161
|
+
console.log(err);
|
|
162
|
+
reject(err);
|
|
163
|
+
});
|
|
359
164
|
|
|
360
|
-
|
|
165
|
+
for (const key in hashTable) {
|
|
166
|
+
const item = hashTable[key];
|
|
361
167
|
|
|
362
|
-
|
|
363
|
-
}
|
|
168
|
+
const value = _longToByteArray(item.value);
|
|
364
169
|
|
|
365
|
-
|
|
366
|
-
|
|
170
|
+
output.write(Buffer.from(_crypt.default.hexToBytes(item.key).concat(value)));
|
|
171
|
+
}
|
|
367
172
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return _context6.stop();
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}, _callee6);
|
|
374
|
-
}));
|
|
375
|
-
return _generateHash128FromZip.apply(this, arguments);
|
|
173
|
+
output.close();
|
|
174
|
+
});
|
|
376
175
|
}
|
|
377
176
|
|
|
378
177
|
function _longToByteArray(long) {
|
|
379
|
-
|
|
380
|
-
|
|
178
|
+
const buffer = new ArrayBuffer(8);
|
|
179
|
+
const longNum = new Float64Array(buffer);
|
|
381
180
|
longNum[0] = long;
|
|
382
181
|
return Array.from(new Uint8Array(buffer)).reverse();
|
|
383
182
|
}
|
|
384
183
|
|
|
385
|
-
function addFileToZip(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
function _addFileToZip() {
|
|
390
|
-
_addFileToZip = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee7(inputFolder, fileName, zipFile, sevenZipExe) {
|
|
391
|
-
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
392
|
-
while (1) {
|
|
393
|
-
switch (_context7.prev = _context7.next) {
|
|
394
|
-
case 0:
|
|
395
|
-
_context7.next = 2;
|
|
396
|
-
return compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
|
|
397
|
-
|
|
398
|
-
case 2:
|
|
399
|
-
console.log("".concat(fileName, " added to ").concat(zipFile, "."));
|
|
400
|
-
|
|
401
|
-
case 3:
|
|
402
|
-
case "end":
|
|
403
|
-
return _context7.stop();
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}, _callee7);
|
|
407
|
-
}));
|
|
408
|
-
return _addFileToZip.apply(this, arguments);
|
|
184
|
+
async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
|
|
185
|
+
await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
|
|
186
|
+
console.log("".concat(fileName, " added to ").concat(zipFile, "."));
|
|
409
187
|
}
|
|
410
188
|
|
|
411
189
|
function appendFileToArchive(archive, subFileName, subFileData) {
|
|
412
|
-
return new Promise(
|
|
413
|
-
|
|
190
|
+
return new Promise(resolve => {
|
|
191
|
+
const fileStream = (0, _fs.createReadStream)(subFileData);
|
|
414
192
|
console.log("Compression start: ".concat(subFileName));
|
|
415
|
-
fileStream.on('close',
|
|
193
|
+
fileStream.on('close', () => {
|
|
416
194
|
console.log("Compression finish: ".concat(subFileName));
|
|
417
195
|
resolve(null);
|
|
418
196
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/utils/compress-util.js"],"names":["compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","process","platform","compressWithChildProcessWindows","compressWithChildProcessUnix","inputFolder","inputFiles","fullOutputFile","args","childProcess","ChildProcessProxy","start","command","arguments","spawn","cwd","wait","sevenZipExe","substr","generateHash128FromZip","inputZipFile","fs","readFile","JSZip","loadAsync","zip","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","MD5Hash","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","_longToByteArray","write","crypt","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGO,SAASA,oBAAT,CAA8BC,QAA9B,EAAwC;AAC7C,MAAMC,kBAAkB,aAAMD,QAAN,QAAxB;AACA,MAAME,IAAI,GAAG,uBAAb;AACA,MAAMC,KAAK,GAAG,0BAAiBH,QAAjB,CAAd;AACA,MAAMI,MAAM,GAAG,2BAAkBH,kBAAlB,CAAf;AAEA,SAAO,IAAII,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtCJ,IAAAA,KAAK,CAACK,EAAN,CAAS,KAAT,EAAgB,YAAM;AACpBC,MAAAA,OAAO,CAACC,GAAR,WAAeT,kBAAf;AACAK,MAAAA,OAAO,CAACL,kBAAD,CAAP;AACD,KAHD;AAIAE,IAAAA,KAAK,CAACK,EAAN,CAAS,OAAT,EAAkB,UAACG,KAAD,EAAW;AAC3BF,MAAAA,OAAO,CAACC,GAAR,WAAeT,kBAAf;AACAM,MAAAA,MAAM,CAACI,KAAD,CAAN;AACD,KAHD;AAIAR,IAAAA,KAAK,CAACS,IAAN,CA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uB,CAAvB,EAA0BD,QAA1B,EAAoC/C,WAApC,CADzB;;AAAA;AAELjC,YAAAA,OAAO,CAACC,GAAR,WAAe+E,QAAf,uBAAoCC,OAApC;;AAFK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAKP,SAASnE,mBAAT,CAA6BN,OAA7B,EAAsCI,WAAtC,EAAmDC,WAAnD,EAAgE;AAC9D,SAAO,IAAIjB,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9B,QAAMqF,UAAU,GAAG,0BAAiBrE,WAAjB,CAAnB;AACAb,IAAAA,OAAO,CAACC,GAAR,8BAAkCW,WAAlC;AACAsE,IAAAA,UAAU,CAACnF,EAAX,CAAc,OAAd,EAAuB,YAAM;AAC3BC,MAAAA,OAAO,CAACC,GAAR,+BAAmCW,WAAnC;AACAf,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD,KAHD;AAIAW,IAAAA,OAAO,CAAC2E,MAAR,CAAeD,UAAf,EAA2B;AAACE,MAAAA,IAAI,EAAExE;AAAP,KAA3B;AACD,GARM,CAAP;AASD","sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function compressFileWithGzip(pathFile) {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\nexport async function compressFilesWithZip(fileMap, outputFile, level = 0) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\nexport async function compressWithChildProcess() {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(...arguments);\n } else {\n await compressWithChildProcessUnix(...arguments);\n }\n}\n\nasync function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\nasync function compressWithChildProcessWindows(\n inputFolder,\n outputFile,\n level = 0,\n inputFiles = join('.', '*'),\n sevenZipExe\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\nexport async function generateHash128FromZip(inputZipFile, outputFile) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = _longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\nfunction _longToByteArray(long) {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = long;\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\nexport async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\nfunction appendFileToArchive(archive, subFileName, subFileData) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"file":"compress-util.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/compress-util.js"],"names":["compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","process","platform","compressWithChildProcessWindows","arguments","compressWithChildProcessUnix","inputFolder","inputFiles","fullOutputFile","args","childProcess","ChildProcessProxy","start","command","spawn","cwd","wait","sevenZipExe","substr","generateHash128FromZip","inputZipFile","fs","readFile","zip","JSZip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","MD5Hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","_longToByteArray","write","crypt","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGO,SAASA,oBAAT,CAA8BC,QAA9B,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O,CAACC,GAAR,8BAAkCY,WAAlC;AACAsE,IAAAA,UAAU,CAACpF,EAAX,CAAc,OAAd,EAAuB,MAAM;AAC3BC,MAAAA,OAAO,CAACC,GAAR,+BAAmCY,WAAnC;AACAhB,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD,KAHD;AAIAY,IAAAA,OAAO,CAAC2E,MAAR,CAAeD,UAAf,EAA2B;AAACE,MAAAA,IAAI,EAAExE;AAAP,KAA3B;AACD,GARM,CAAP;AASD","sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function compressFileWithGzip(pathFile) {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\nexport async function compressFilesWithZip(fileMap, outputFile, level = 0) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\nexport async function compressWithChildProcess() {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(...arguments);\n } else {\n await compressWithChildProcessUnix(...arguments);\n }\n}\n\nasync function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\nasync function compressWithChildProcessWindows(\n inputFolder,\n outputFile,\n level = 0,\n inputFiles = join('.', '*'),\n sevenZipExe\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\nexport async function generateHash128FromZip(inputZipFile, outputFile) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = _longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\nfunction _longToByteArray(long) {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = long;\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\nexport async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\nfunction appendFileToArchive(archive, subFileName, subFileData) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"file":"compress-util.js"}
|