all files / core/compression/ ascii-85-stream.js

31.34% Statements 21/67
40.74% Branches 11/27
80% Functions 8/10
28.13% Lines 18/64
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                           
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../decode-stream", "../utils"], function (require, exports, decode_stream_1, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfAscii85Stream = (function (_super) {
        __extends(_PdfAscii85Stream, _super);
        function _PdfAscii85Stream(str, maybeLength) {
            var _this = this;
            if (maybeLength) {
                maybeLength *= 0.8;
            }
            _this = _super.call(this, maybeLength) || this;
            _this.stream = str;
            _this.input = new Uint8Array(5);
            return _this;
        }
        _PdfAscii85Stream.prototype.readBlock = function () {
            var tildaCharacter = 0x7e;
            var lowerCharacter = 0x7a;
            var eof = -1;
            var str = this.stream;
            var c = str.getByte();
            while (utils_1._isWhiteSpace(c)) {
                c = str.getByte();
            }
            if (c === eof || c === tildaCharacter) {
                this.eof = true;
                return;
            }
            var bufferLength = this.bufferLength;
            var buffer;
            var i;
            if (c === lowerCharacter) {
                buffer = this.ensureBuffer(bufferLength + 4);
                for (i = 0; i < 4; ++i) {
                    buffer[bufferLength + i] = 0;
                }
                this.bufferLength += 4;
            }
            else {
                var input = this.input;
                input[0] = c;
                for (i = 1; i < 5; ++i) {
                    c = str.getByte();
                    while (utils_1._isWhiteSpace(c)) {
                        c = str.getByte();
                    }
                    input[Number.parseInt(i.toString(), 10)] = c;
                    if (c === eof || c === tildaCharacter) {
                        break;
                    }
                }
                buffer = this.ensureBuffer(bufferLength + i - 1);
                this.bufferLength += i - 1;
                if (i < 5) {
                    for (; i < 5; ++i) {
                        input[Number.parseInt(i.toString(), 10)] = 0x21 + 84;
                    }
                    this.eof = true;
                }
                var t = 0;
                for (i = 0; i < 5; ++i) {
                    t = t * 85 + (input[Number.parseInt(i.toString(), 10)] - 0x21);
                }
                for (i = 3; i >= 0; --i) {
                    buffer[bufferLength + i] = t & 0xff;
                    t >>= 8;
                }
            }
        };
        return _PdfAscii85Stream;
    }(decode_stream_1._PdfDecodeStream));
    exports._PdfAscii85Stream = _PdfAscii85Stream;
});