react / wstein / node_modules / browserify / node_modules / browserify-zlib / node_modules / pako / lib / utils / common.js
80547 views'use strict';123var TYPED_OK = (typeof Uint8Array !== 'undefined') &&4(typeof Uint16Array !== 'undefined') &&5(typeof Int32Array !== 'undefined');678exports.assign = function (obj /*from1, from2, from3, ...*/) {9var sources = Array.prototype.slice.call(arguments, 1);10while (sources.length) {11var source = sources.shift();12if (!source) { continue; }1314if (typeof(source) !== 'object') {15throw new TypeError(source + 'must be non-object');16}1718for (var p in source) {19if (source.hasOwnProperty(p)) {20obj[p] = source[p];21}22}23}2425return obj;26};272829// reduce buffer size, avoiding mem copy30exports.shrinkBuf = function (buf, size) {31if (buf.length === size) { return buf; }32if (buf.subarray) { return buf.subarray(0, size); }33buf.length = size;34return buf;35};363738var fnTyped = {39arraySet: function (dest, src, src_offs, len, dest_offs) {40if (src.subarray && dest.subarray) {41dest.set(src.subarray(src_offs, src_offs+len), dest_offs);42return;43}44// Fallback to ordinary array45for(var i=0; i<len; i++) {46dest[dest_offs + i] = src[src_offs + i];47}48},49// Join array of chunks to single array.50flattenChunks: function(chunks) {51var i, l, len, pos, chunk, result;5253// calculate data length54len = 0;55for (i=0, l=chunks.length; i<l; i++) {56len += chunks[i].length;57}5859// join chunks60result = new Uint8Array(len);61pos = 0;62for (i=0, l=chunks.length; i<l; i++) {63chunk = chunks[i];64result.set(chunk, pos);65pos += chunk.length;66}6768return result;69}70};7172var fnUntyped = {73arraySet: function (dest, src, src_offs, len, dest_offs) {74for(var i=0; i<len; i++) {75dest[dest_offs + i] = src[src_offs + i];76}77},78// Join array of chunks to single array.79flattenChunks: function(chunks) {80return [].concat.apply([], chunks);81}82};838485// Enable/Disable typed arrays use, for testing86//87exports.setTyped = function (on) {88if (on) {89exports.Buf8 = Uint8Array;90exports.Buf16 = Uint16Array;91exports.Buf32 = Int32Array;92exports.assign(exports, fnTyped);93} else {94exports.Buf8 = Array;95exports.Buf16 = Array;96exports.Buf32 = Array;97exports.assign(exports, fnUntyped);98}99};100101exports.setTyped(TYPED_OK);102103