all files / core/ decode-stream.js

78.16% Statements 68/87
60% Branches 21/35
68.42% Functions 13/19
77.38% Lines 65/84
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125                                  11× 11×     11× 11×   11× 11× 11× 11×   16799× 16799×       16799×                                   53×         51× 51×       53×                        
/* 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", "./base-stream"], function (require, exports, base_stream_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfDecodeStream = (function (_super) {
        __extends(_PdfDecodeStream, _super);
        function _PdfDecodeStream(maybeMinBufferLength) {
            var _this = _super.call(this) || this;
            _this._rawMinBufferLength = maybeMinBufferLength || 0;
            _this.offset = 0;
            _this.bufferLength = 0;
            _this.eof = false;
            _this.buffer = new Uint8Array(0);
            _this.minBufferLength = 512;
            Eif (maybeMinBufferLength) {
                while (_this.minBufferLength < maybeMinBufferLength) {
                    _this.minBufferLength *= 2;
                }
            }
            return _this;
        }
        Object.defineProperty(_PdfDecodeStream.prototype, "isEmpty", {
            get: function () {
                while (!this.eof && this.bufferLength === 0) {
                    this.readBlock();
                }
                return this.bufferLength === 0;
            },
            enumerable: true,
            configurable: true
        });
        _PdfDecodeStream.prototype.ensureBuffer = function (requested) {
            var buffer = this.buffer;
            Iif (requested <= buffer.byteLength) {
                return buffer;
            }
            var size = this.minBufferLength;
            while (size < requested) {
                size *= 2;
            }
            var buffer2 = new Uint8Array(size);
            buffer2.set(buffer);
            this.buffer = buffer2;
            return this.buffer;
        };
        _PdfDecodeStream.prototype.getByte = function () {
            var position = this.offset;
            while (this.bufferLength <= position) {
                Iif (this.eof) {
                    return -1;
                }
                this.readBlock();
            }
            return this.buffer[this.offset++];
        };
        _PdfDecodeStream.prototype.getBytes = function (length) {
            var position = this.offset;
            var end;
            Iif (length) {
                this.ensureBuffer(position + length);
                end = position + length;
                while (!this.eof && this.bufferLength < end) {
                    this.readBlock();
                }
                var bufEnd = this.bufferLength;
                if (end > bufEnd) {
                    end = bufEnd;
                }
            }
            else {
                while (!this.eof) {
                    this.readBlock();
                }
                end = this.bufferLength;
            }
            this.offset = end;
            return this.buffer.subarray(position, end);
        };
        _PdfDecodeStream.prototype.reset = function () {
            this.offset = 0;
        };
        _PdfDecodeStream.prototype.makeSubStream = function (start, length, dictionary) {
            if (length === undefined) {
                while (!this.eof) {
                    this.readBlock();
                }
            }
            else {
                var end = start + length;
                while (this.bufferLength <= end && !this.eof) {
                    this.readBlock();
                }
            }
            return new base_stream_1._PdfStream(this.buffer, dictionary, start, length);
        };
        _PdfDecodeStream.prototype.getBaseStreams = function () {
            return this.stream ? this.stream.getBaseStreams() : null;
        };
        _PdfDecodeStream.prototype.moveStart = function () {
            throw new Error('Invalid call from decode stream');
        };
        _PdfDecodeStream.prototype.getByteRange = function (begin, end) {
            throw new Error('Invalid call from decode stream. begin: ' + begin + ', end: ' + end);
        };
        _PdfDecodeStream.prototype.readBlock = function () {
            throw new Error('Invalid call from decode stream');
        };
        return _PdfDecodeStream;
    }(base_stream_1._PdfBaseStream));
    exports._PdfDecodeStream = _PdfDecodeStream;
});