2
0

base_stream.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.BaseStream = void 0;
  27. var _util = require("../shared/util.js");
  28. class BaseStream {
  29. constructor() {
  30. if (this.constructor === BaseStream) {
  31. (0, _util.unreachable)("Cannot initialize BaseStream.");
  32. }
  33. }
  34. get length() {
  35. (0, _util.unreachable)("Abstract getter `length` accessed");
  36. }
  37. get isEmpty() {
  38. (0, _util.unreachable)("Abstract getter `isEmpty` accessed");
  39. }
  40. get isDataLoaded() {
  41. return (0, _util.shadow)(this, "isDataLoaded", true);
  42. }
  43. getByte() {
  44. (0, _util.unreachable)("Abstract method `getByte` called");
  45. }
  46. getBytes(length) {
  47. (0, _util.unreachable)("Abstract method `getBytes` called");
  48. }
  49. peekByte() {
  50. const peekedByte = this.getByte();
  51. if (peekedByte !== -1) {
  52. this.pos--;
  53. }
  54. return peekedByte;
  55. }
  56. peekBytes(length) {
  57. const bytes = this.getBytes(length);
  58. this.pos -= bytes.length;
  59. return bytes;
  60. }
  61. getUint16() {
  62. const b0 = this.getByte();
  63. const b1 = this.getByte();
  64. if (b0 === -1 || b1 === -1) {
  65. return -1;
  66. }
  67. return (b0 << 8) + b1;
  68. }
  69. getInt32() {
  70. const b0 = this.getByte();
  71. const b1 = this.getByte();
  72. const b2 = this.getByte();
  73. const b3 = this.getByte();
  74. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  75. }
  76. getByteRange(begin, end) {
  77. (0, _util.unreachable)("Abstract method `getByteRange` called");
  78. }
  79. getString(length) {
  80. return (0, _util.bytesToString)(this.getBytes(length));
  81. }
  82. skip(n) {
  83. this.pos += n || 1;
  84. }
  85. reset() {
  86. (0, _util.unreachable)("Abstract method `reset` called");
  87. }
  88. moveStart() {
  89. (0, _util.unreachable)("Abstract method `moveStart` called");
  90. }
  91. makeSubStream(start, length, dict = null) {
  92. (0, _util.unreachable)("Abstract method `makeSubStream` called");
  93. }
  94. getBaseStreams() {
  95. return null;
  96. }
  97. }
  98. exports.BaseStream = BaseStream;