1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.Ascii85Stream = void 0;
|
28 |
|
29 | var _decode_stream = require("./decode_stream.js");
|
30 |
|
31 | var _core_utils = require("./core_utils.js");
|
32 |
|
33 | class 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 |
|
116 | exports.Ascii85Stream = Ascii85Stream; |
\ | No newline at end of file |