UNPKG

2.63 kBJavaScriptView Raw
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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.Ascii85Stream = void 0;
28
29var _decode_stream = require("./decode_stream.js");
30
31var _core_utils = require("./core_utils.js");
32
33class Ascii85Stream extends _decode_stream.DecodeStream {
34 constructor(str, maybeLength) {
35 if (maybeLength) {
36 maybeLength *= 0.8;
37 }
38
39 super(maybeLength);
40 this.str = str;
41 this.dict = str.dict;
42 this.input = new Uint8Array(5);
43 }
44
45 readBlock() {
46 const TILDA_CHAR = 0x7e;
47 const Z_LOWER_CHAR = 0x7a;
48 const EOF = -1;
49 const str = this.str;
50 let c = str.getByte();
51
52 while ((0, _core_utils.isWhiteSpace)(c)) {
53 c = str.getByte();
54 }
55
56 if (c === EOF || c === TILDA_CHAR) {
57 this.eof = true;
58 return;
59 }
60
61 const bufferLength = this.bufferLength;
62 let buffer, i;
63
64 if (c === Z_LOWER_CHAR) {
65 buffer = this.ensureBuffer(bufferLength + 4);
66
67 for (i = 0; i < 4; ++i) {
68 buffer[bufferLength + i] = 0;
69 }
70
71 this.bufferLength += 4;
72 } else {
73 const input = this.input;
74 input[0] = c;
75
76 for (i = 1; i < 5; ++i) {
77 c = str.getByte();
78
79 while ((0, _core_utils.isWhiteSpace)(c)) {
80 c = str.getByte();
81 }
82
83 input[i] = c;
84
85 if (c === EOF || c === TILDA_CHAR) {
86 break;
87 }
88 }
89
90 buffer = this.ensureBuffer(bufferLength + i - 1);
91 this.bufferLength += i - 1;
92
93 if (i < 5) {
94 for (; i < 5; ++i) {
95 input[i] = 0x21 + 84;
96 }
97
98 this.eof = true;
99 }
100
101 let t = 0;
102
103 for (i = 0; i < 5; ++i) {
104 t = t * 85 + (input[i] - 0x21);
105 }
106
107 for (i = 3; i >= 0; --i) {
108 buffer[bufferLength + i] = t & 0xff;
109 t >>= 8;
110 }
111 }
112 }
113
114}
115
116exports.Ascii85Stream = Ascii85Stream;
\No newline at end of file