all files / core/compression/ decompressed-output.js

19.7% Statements 13/66
0% Branches 0/17
25% Functions 2/8
19.7% Lines 13/66
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                                                                                                                                                                        
define(["require", "exports", "./../utils"], function (require, exports, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _DecompressedOutput = (function () {
        function _DecompressedOutput() {
            this._end = 0;
            this._usedBytes = 0;
            this._dOutput = Array(_DecompressedOutput._dOutSize).fill(0);
            this._end = 0;
            this._usedBytes = 0;
        }
        Object.defineProperty(_DecompressedOutput.prototype, "_unusedBytes", {
            get: function () {
                return _DecompressedOutput._dOutSize - this._usedBytes;
            },
            enumerable: true,
            configurable: true
        });
        _DecompressedOutput.prototype._write = function (b) {
            this._dOutput[this._end++] = b;
            this._end &= _DecompressedOutput._dOutMask;
            ++this._usedBytes;
        };
        _DecompressedOutput.prototype._writeLD = function (length, distance) {
            this._usedBytes += length;
            var copyStart = (this._end - distance) & _DecompressedOutput._dOutMask;
            var border = _DecompressedOutput._dOutSize - length;
            if (copyStart <= border && this._end < border) {
                if (length <= distance) {
                    utils_1._copyRange(this._dOutput, this._end, this._dOutput, copyStart, copyStart + length);
                    this._end += length;
                }
                else {
                    while (length-- > 0) {
                        this._dOutput[this._end++] = this._dOutput[copyStart++];
                    }
                }
            }
            else {
                while (length-- > 0) {
                    this._dOutput[this._end++] = this._dOutput[copyStart++];
                    this._end &= _DecompressedOutput._dOutMask;
                    copyStart &= _DecompressedOutput._dOutMask;
                }
            }
        };
        _DecompressedOutput.prototype._copyFrom = function (input, length) {
            length = Math.min(Math.min(length, _DecompressedOutput._dOutSize - this._usedBytes), input._bytes);
            var copied;
            var tailLen = _DecompressedOutput._dOutSize - this._end;
            if (length > tailLen) {
                copied = input._copyTo(this._dOutput, this._end, tailLen);
                if (copied === tailLen) {
                    copied += input._copyTo(this._dOutput, 0, length - tailLen);
                }
            }
            else {
                copied = input._copyTo(this._dOutput, this._end, length);
            }
            this._end = (this._end + copied) & _DecompressedOutput._dOutMask;
            this._usedBytes += copied;
            return copied;
        };
        _DecompressedOutput.prototype._copyTo = function (output, offset, length) {
            var end;
            if (length > this._usedBytes) {
                end = this._end;
                length = this._usedBytes;
            }
            else {
                end = (this._end - this._usedBytes + length) & _DecompressedOutput._dOutMask;
            }
            var copied = length;
            var tailLen = length - end;
            var sourceStart = _DecompressedOutput._dOutSize - tailLen;
            if (tailLen > 0) {
                for (var i = 0; i < tailLen && i + sourceStart < this._dOutput.length && i + offset < output.length; i++) {
                    output[offset + i] = this._dOutput[sourceStart + i];
                }
                var sourceStartIndex_1 = _DecompressedOutput._dOutSize - tailLen;
                utils_1._copyRange(output, offset, this._dOutput, sourceStartIndex_1, sourceStartIndex_1 + tailLen);
                offset += tailLen;
                length = end;
            }
            sourceStart = end - length;
            var sourceStartIndex = end - length;
            utils_1._copyRange(output, offset, this._dOutput, sourceStartIndex, end);
            this._usedBytes -= copied;
            return { 'count': copied, 'data': output };
        };
        _DecompressedOutput._dOutSize = 32768;
        _DecompressedOutput._dOutMask = 32767;
        return _DecompressedOutput;
    }());
    exports._DecompressedOutput = _DecompressedOutput;
});