test_utils.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.NodeCMapReaderFactory = undefined;
  20. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  21. var _util = require('../../shared/util');
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. var NodeCMapReaderFactory = function () {
  24. function NodeCMapReaderFactory(params) {
  25. _classCallCheck(this, NodeCMapReaderFactory);
  26. this.baseUrl = params.baseUrl || null;
  27. this.isCompressed = params.isCompressed || false;
  28. }
  29. _createClass(NodeCMapReaderFactory, [{
  30. key: 'fetch',
  31. value: function fetch(params) {
  32. var _this = this;
  33. var name = params.name;
  34. if (!name) {
  35. return Promise.reject(new Error('CMap name must be specified.'));
  36. }
  37. return new Promise(function (resolve, reject) {
  38. var url = _this.baseUrl + name + (_this.isCompressed ? '.bcmap' : '');
  39. var fs = require('fs');
  40. fs.readFile(url, function (error, data) {
  41. if (error || !data) {
  42. reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url));
  43. return;
  44. }
  45. resolve({
  46. cMapData: new Uint8Array(data),
  47. compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE
  48. });
  49. });
  50. });
  51. }
  52. }]);
  53. return NodeCMapReaderFactory;
  54. }();
  55. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;