all files / core/compression/ in-buffer.js

21.33% Statements 16/75
0% Branches 0/29
15.38% Functions 2/13
21.33% Lines 16/75
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                                                                                                                                                                                        
define(["require", "exports", "./../utils"], function (require, exports, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _InBuffer = (function () {
        function _InBuffer() {
            this._bBuffer = 0;
            this._bInBuffer = 0;
            this._begin = 0;
            this._end = 0;
        }
        Object.defineProperty(_InBuffer.prototype, "_bytes", {
            get: function () {
                return (this._end - this._begin) + Math.floor(this._bInBuffer / 8);
            },
            enumerable: true,
            configurable: true
        });
        _InBuffer.prototype._needsInput = function () {
            return this._begin === this._end;
        };
        _InBuffer.prototype._availableBits = function (count) {
            if (this._bInBuffer < count) {
                if (this._needsInput()) {
                    return false;
                }
                this._bBuffer |= utils_1._toUnsigned(this._buffer[this._begin++], 32) << this._bInBuffer;
                this._bInBuffer += 8;
                if (this._bInBuffer < count) {
                    if (this._needsInput()) {
                        return false;
                    }
                    this._bBuffer |= utils_1._toUnsigned(this._buffer[this._begin++], 32) << this._bInBuffer;
                    this._bInBuffer += 8;
                }
            }
            return true;
        };
        _InBuffer.prototype._load16Bits = function () {
            if (this._bInBuffer < 8) {
                if (this._begin < this._end) {
                    this._bBuffer |= utils_1._toUnsigned(this._buffer[this._begin++], 32) << this._bInBuffer;
                    this._bInBuffer += 8;
                }
                if (this._begin < this._end) {
                    this._bBuffer |= utils_1._toUnsigned(this._buffer[this._begin++], 32) << this._bInBuffer;
                    this._bInBuffer += 8;
                }
            }
            else if (this._bInBuffer < 16) {
                if (this._begin < this._end) {
                    this._bBuffer |= utils_1._toUnsigned(this._buffer[this._begin++], 32) << this._bInBuffer;
                    this._bInBuffer += 8;
                }
            }
            return this._bBuffer;
        };
        _InBuffer.prototype._getBitMask = function (count) {
            return (utils_1._toUnsigned(1, 32) << count) - 1;
        };
        _InBuffer.prototype._getBits = function (count) {
            if (!this._availableBits(count)) {
                return -1;
            }
            var result = this._bBuffer & this._getBitMask(count);
            this._bBuffer >>= count;
            this._bInBuffer -= count;
            return result;
        };
        _InBuffer.prototype._copyTo = function (output, offset, length) {
            var bitBuffer = 0;
            while (this._bInBuffer > 0 && length > 0) {
                output[offset++] = utils_1._toUnsigned(this._bBuffer, 8);
                this._bBuffer >>= 8;
                this._bInBuffer -= 8;
                length--;
                bitBuffer++;
            }
            if (length === 0) {
                return bitBuffer;
            }
            var avail = this._end - this._begin;
            if (length > avail) {
                length = avail;
            }
            for (var i = 0; i < length && i + this._begin < this._buffer.length && i + offset < output.length; i++) {
                output[offset + i] = this._buffer[this._begin + i];
            }
            this._begin += length;
            return bitBuffer + length;
        };
        _InBuffer.prototype._setInput = function (buffer, offset, length) {
            this._buffer = buffer;
            this._begin = offset;
            this._end = offset + length;
        };
        _InBuffer.prototype._skipBits = function (n) {
            this._bBuffer >>= n;
            this._bInBuffer -= n;
        };
        _InBuffer.prototype._skipByteBoundary = function () {
            this._bBuffer >>= this._bInBuffer % 8;
            this._bInBuffer = this._bInBuffer - (this._bInBuffer % 8);
        };
        return _InBuffer;
    }());
    exports._InBuffer = _InBuffer;
});