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

36.84% Statements 21/57
31.43% Branches 11/35
80% Functions 8/10
33.33% Lines 18/54
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                                                                                                                     
/* 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"], function (require, exports, decode_stream_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfAsciiHexStream = (function (_super) {
        __extends(_PdfAsciiHexStream, _super);
        function _PdfAsciiHexStream(str, maybeLength) {
            var _this = this;
            if (maybeLength) {
                maybeLength *= 0.5;
            }
            _this = _super.call(this, maybeLength) || this;
            _this.stream = str;
            _this.firstDigit = -1;
            return _this;
        }
        _PdfAsciiHexStream.prototype.readBlock = function () {
            var blockSize = 8000;
            var bytes = this.stream.getBytes(blockSize);
            if (!bytes.length) {
                this.eof = true;
                return;
            }
            var maxDecodeLength = (bytes.length + 1) >> 1;
            var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
            var bufferLength = this.bufferLength;
            var firstDigit = this.firstDigit;
            for (var _i = 0, bytes_1 = bytes; _i < bytes_1.length; _i++) {
                var ch = bytes_1[_i];
                var digit = void 0;
                if (ch >= 0x30 && ch <= 0x39) {
                    digit = ch & 0x0f;
                }
                else if ((ch >= 0x41 && ch <= 0x46) ||
                    (ch >= 0x61 && ch <= 0x66)) {
                    digit = (ch & 0x0f) + 9;
                }
                else if (ch === 0x3e) {
                    this.eof = true;
                    break;
                }
                else {
                    continue;
                }
                if (firstDigit < 0) {
                    firstDigit = digit;
                }
                else {
                    buffer[bufferLength++] = (firstDigit << 4) | digit;
                    firstDigit = -1;
                }
            }
            if (firstDigit >= 0 && this.eof) {
                buffer[bufferLength++] = firstDigit << 4;
                firstDigit = -1;
            }
            this.firstDigit = firstDigit;
            this.bufferLength = bufferLength;
        };
        return _PdfAsciiHexStream;
    }(decode_stream_1._PdfDecodeStream));
    exports._PdfAsciiHexStream = _PdfAsciiHexStream;
});