all files / graphics/images/ byte-array.js

76.56% Statements 49/64
50% Branches 1/2
46.15% Functions 6/13
76.56% Lines 49/64
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                                           15775× 15775× 15775× 15775× 15775× 15775× 15775× 15775× 15775× 15775×                                                  
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ByteArray = (function () {
        function ByteArray(length) {
            this.mPosition = 0;
            this.buffer = new Uint8Array(length);
            this.dataView = new DataView(this.buffer.buffer);
        }
        Object.defineProperty(ByteArray.prototype, "position", {
            get: function () {
                return this.mPosition;
            },
            set: function (value) {
                this.mPosition = value;
            },
            enumerable: true,
            configurable: true
        });
        ByteArray.prototype.read = function (buffer, offset, count) {
            for (var index = offset; index < count; index++) {
                var position = this.position;
                buffer.buffer[index] = this.readByte(position);
                this.position++;
            }
        };
        ByteArray.prototype.getBuffer = function (index) {
            return this.buffer[index];
        };
        ByteArray.prototype.writeFromBase64String = function (base64) {
            var arr = this.encodedString(base64);
            this.buffer = arr;
        };
        ByteArray.prototype.encodedString = function (input) {
            var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
            var chr1;
            var chr2;
            var chr3;
            var enc1;
            var enc2;
            var enc3;
            var enc4;
            var i = 0;
            var resultIndex = 0;
            var dataUrlPrefix = 'data:';
            input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
            var totalLength = input.length * 3 / 4;
            Eif (input.charAt(input.length - 1) === keyStr.charAt(64)) {
                totalLength--;
            }
            var output = new Uint8Array(totalLength | 0);
            while (i < input.length) {
                enc1 = keyStr.indexOf(input.charAt(i++));
                enc2 = keyStr.indexOf(input.charAt(i++));
                enc3 = keyStr.indexOf(input.charAt(i++));
                enc4 = keyStr.indexOf(input.charAt(i++));
                chr1 = (enc1 << 2) | (enc2 >> 4);
                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                chr3 = ((enc3 & 3) << 6) | enc4;
                output[resultIndex++] = chr1;
                output[resultIndex++] = chr2;
                output[resultIndex++] = chr3;
            }
            return output;
        };
        ByteArray.prototype.readByte = function (offset) {
            return (this.buffer[offset]);
        };
        Object.defineProperty(ByteArray.prototype, "internalBuffer", {
            get: function () {
                return this.buffer;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "count", {
            get: function () {
                return this.buffer.byteLength;
            },
            enumerable: true,
            configurable: true
        });
        ByteArray.prototype.readNextTwoBytes = function (stream) {
            var data = stream.readByte(this.position);
            this.position++;
            data <<= 8;
            data |= stream.readByte(this.position);
            this.position++;
            return data;
        };
        return ByteArray;
    }());
    exports.ByteArray = ByteArray;
});