test_utils.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(_ref) {
  25. var _ref$baseUrl = _ref.baseUrl,
  26. baseUrl = _ref$baseUrl === undefined ? null : _ref$baseUrl,
  27. _ref$isCompressed = _ref.isCompressed,
  28. isCompressed = _ref$isCompressed === undefined ? false : _ref$isCompressed;
  29. _classCallCheck(this, NodeCMapReaderFactory);
  30. this.baseUrl = baseUrl;
  31. this.isCompressed = isCompressed;
  32. }
  33. _createClass(NodeCMapReaderFactory, [{
  34. key: 'fetch',
  35. value: function fetch(_ref2) {
  36. var _this = this;
  37. var name = _ref2.name;
  38. if (!name) {
  39. return Promise.reject(new Error('CMap name must be specified.'));
  40. }
  41. return new Promise(function (resolve, reject) {
  42. var url = _this.baseUrl + name + (_this.isCompressed ? '.bcmap' : '');
  43. var fs = require('fs');
  44. fs.readFile(url, function (error, data) {
  45. if (error || !data) {
  46. reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url));
  47. return;
  48. }
  49. resolve({
  50. cMapData: new Uint8Array(data),
  51. compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE
  52. });
  53. });
  54. });
  55. }
  56. }]);
  57. return NodeCMapReaderFactory;
  58. }();
  59. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;