Makes UTF8 decoding function.
@param  {Boolean} [chunkType] Specifies type of input chunks.
@return {Function} The function to decode byte chunks.
971747
function makeDecoder(chunkType) {
	if (chunkType === BUFFER) {
		return function (buf) {
			return buf.toString('utf8');
		};
	}
	if (isnode) {
		return function (a) {
			return new Buffer(a).toString('utf8');
		};
	}
	var decoder = null;
	return function (buf) {
		if (!decoder) {
			decoder = new TextDecoder();
		}
		return decoder.decode(buf);
	};
}
949796
def utf8(value):
    
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")
783745
function bytesToString(arr) {
    if (arr instanceof ArrayBuffer) {
        arr = new Uint8Array(arr);
    }
    return textDecoder.decode(arr);
}
1042090
function _bnToBytes(b) {
  // prepend 0x00 if first byte >= 0x80
  var hex = b.toString(16);
  if(hex[0] >= '8') {
    hex = '00' + hex;
  }
  return forge.util.hexToBytes(hex);
}
895777
function decode (data, start, end, encoding) {
  if (data == null || data.length === 0) {
    return null
  }

  if (typeof start !== 'number' && encoding == null) {
    encoding = start
    start = undefined
  }

  if (typeof end !== 'number' && encoding == null) {
    encoding = end
    end = undefined
  }

  decode.position = 0
  decode.encoding = encoding || null

  decode.data = !(Buffer.isBuffer(data))
    ? Buffer.from(data)
    : data.slice(start, end)

  decode.bytes = decode.data.length

  return decode.next()
}
715203
function decompress( buffer ) {

  var chunks = []
  var chunkType = ADC.CHUNK_UNKNOWN
  var position = 0
  var length = 0

  windowOffset = 0

  while( position < buffer.length ) {
    chunkType = ADC.getChunkType( buffer[ position ] )
    length = ADC.getSequenceLength( buffer[ position ] )
    switch( chunkType ) {
      case ADC.CHUNK_DATA:
        chunks.push( decodeData( window, buffer, position ) )
        break
      case ADC.CHUNK_THREE:
        chunks.push( decodeRunlength( window, buffer, position ) )
        break
      case ADC.CHUNK_TWO:
        chunks.push( decodeRunlength( window, buffer, position ) )
        break
      default:
        throw new Error( 'Unknown chunk type 0x' + buffer[ position ].toString(16) + ' at ' + position )
    }
    position += length
  }

  return Buffer.concat( chunks )

}
674068
def chunklentype(self):
        
        x = self.file.read(8)
        if not x:
            return None
        if len(x) != 8:
            raise FormatError(
              'End of file whilst reading chunk length and type.')
        length, chunk_type = struct.unpack('!I4s', x)
        chunk_type = bytestostr(chunk_type)
        if length > 2**31-1:
            raise FormatError('Chunk %s is too large: %d.' % (chunk_type,
                                                              length))
        return length, chunk_type
500123
function isBinary(buffer) {
  var chunk = buffer.toString('utf8', 0, Math.min(buffer.length, 24));
  for (var i in chunk) {
    var charCode = chunk.charCodeAt(i);
    if (charCode == 65533 || charCode <= 8) {
      return true;
    }
  }
  return false;
}
1024410
def unpack_chunk(chunk_data: str) -> bytes:
    

    if not chunk_data:
        return b''

    chunk_compressed = binascii.a2b_base64(chunk_data.encode('utf-8'))
    return zlib.decompress(chunk_compressed)
347109
function UTF16Decoder(utf16_be, options) {
    var fatal = options.fatal;
    var /** @type {?number} */ utf16_lead_byte = null,
        /** @type {?number} */ utf16_lead_surrogate = null;
    /**
     * @param {Stream} stream The stream of bytes being decoded.
     * @param {number} bite The next byte read from the stream.
     * @return {?(number|!Array.<number>)} The next code point(s)
     *     decoded, or null if not enough data exists in the input
     *     stream to decode a complete code point.
     */
    this.handler = function(stream, bite) {
      // 1. If byte is end-of-stream and either utf-16 lead byte or
      // utf-16 lead surrogate is not null, set utf-16 lead byte and
      // utf-16 lead surrogate to null, and return error.
      if (bite === end_of_stream && (utf16_lead_byte !== null ||
                                utf16_lead_surrogate !== null)) {
        return decoderError(fatal);
      }

      // 2. If byte is end-of-stream and utf-16 lead byte and utf-16
      // lead surrogate are null, return finished.
      if (bite === end_of_stream && utf16_lead_byte === null &&
          utf16_lead_surrogate === null) {
        return finished;
      }

      // 3. If utf-16 lead byte is null, set utf-16 lead byte to byte
      // and return continue.
      if (utf16_lead_byte === null) {
        utf16_lead_byte = bite;
        return null;
      }

      // 4. Let code unit be the result of:
      var code_unit;
      if (utf16_be) {
        // utf-16be decoder flag is set
        //   (utf-16 lead byte << 8) + byte.
        code_unit = (utf16_lead_byte << 8) + bite;
      } else {
        // utf-16be decoder flag is unset
        //   (byte << 8) + utf-16 lead byte.
        code_unit = (bite << 8) + utf16_lead_byte;
      }
      // Then set utf-16 lead byte to null.
      utf16_lead_byte = null;

      // 5. If utf-16 lead surrogate is not null, let lead surrogate
      // be utf-16 lead surrogate, set utf-16 lead surrogate to null,
      // and then run these substeps:
      if (utf16_lead_surrogate !== null) {
        var lead_surrogate = utf16_lead_surrogate;
        utf16_lead_surrogate = null;

        // 1. If code unit is in the range U+DC00 to U+DFFF, return a
        // code point whose value is 0x10000 + ((lead surrogate −
        // 0xD800) << 10) + (code unit − 0xDC00).
        if (inRange(code_unit, 0xDC00, 0xDFFF)) {
          return 0x10000 + (lead_surrogate - 0xD800) * 0x400 +
              (code_unit - 0xDC00);
        }

        // 2. Prepend the sequence resulting of converting code unit
        // to bytes using utf-16be decoder flag to stream and return
        // error.
        stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be));
        return decoderError(fatal);
      }

      // 6. If code unit is in the range U+D800 to U+DBFF, set utf-16
      // lead surrogate to code unit and return continue.
      if (inRange(code_unit, 0xD800, 0xDBFF)) {
        utf16_lead_surrogate = code_unit;
        return null;
      }

      // 7. If code unit is in the range U+DC00 to U+DFFF, return
      // error.
      if (inRange(code_unit, 0xDC00, 0xDFFF))
        return decoderError(fatal);

      // 8. Return code point code unit.
      return code_unit;
    };
  }
717694
def _ensure_decoded(s):
    
    if isinstance(s, np.bytes_):
        s = s.decode('UTF-8')
    return s
1038958
function utf8Substr(str, startInBytes, lengthInBytes) {
	const strBytes = stringToByteArray(str);
	const subStrBytes = [];
	let count = 0;

	for (let i = startInBytes; count < lengthInBytes; i++) {
		subStrBytes.push(strBytes[i]);
		count++;
	}

	return byteArrayToString(subStrBytes);

	// Converts the byte array to a UTF-8 string.
	// From http://stackoverflow.com/questions/1240408/reading-bytes-from-a-javascript-string?lq=1
	function byteArrayToString(byteArray) {
		let str = '';
		for (let i = 0; i < byteArray.length; i++) {
			str += byteArray[i] <= 0x7F ? byteArray[i] === 0x25 ? '%25' : // %
				String.fromCharCode(byteArray[i]) : '%' + byteArray[i].toString(16).toUpperCase();
		}

		return decodeURIComponent(str);
	}
}
630023
private static ChunkType mapChunkType(byte type) {
        if (type == 0) {
            return ChunkType.COMPRESSED_DATA;
        } else if (type == 1) {
            return ChunkType.UNCOMPRESSED_DATA;
        } else if (type == (byte) 0xff) {
            return ChunkType.STREAM_IDENTIFIER;
        } else if ((type & 0x80) == 0x80) {
            return ChunkType.RESERVED_SKIPPABLE;
        } else {
            return ChunkType.RESERVED_UNSKIPPABLE;
        }
    }
1181303
function decode (str) {
  return str.trim().split(' ').map((s) => {
    if (s.charCodeAt(0) - 0x2800 > 127) return s
    return String.fromCharCode(s.charCodeAt(0) - 0x2800)
  }).join('')
}
863824
function _bst(chunk, type) {
  // we should have already read the chunk
  var len = this._int(chunk, type), buf;
  if(!isNaN(len)) {
    // read an integer less than zero, treat as null
    if(len < 0) return null;
    // read in the entire bulk string and swallow the crlf
    if((chunk.length - this._offset) >= len + 2) {
      buf = chunk.slice(this._offset, this._offset + len);
      this._offset += (len + 2);
      //this._buffer = this._buffer.slice(this._offset, this._buffer.length);
      //console.dir(buf);
      return this.buffers ? buf : '' + buf;
    }else{
      this._wait();
    }
  }
}
1270702
function(asUTF8) {
    var result = getRawData(this);
    if (result === null || typeof result === "undefined") {
        return "";
    }
    // if the data is a base64 string, we decode it before checking the encoding !
    if (this.options.base64) {
        result = base64.decode(result);
    }
    if (asUTF8 && this.options.binary) {
        // JSZip.prototype.utf8decode supports arrays as input
        // skip to array => string step, utf8decode will do it.
        result = out.utf8decode(result);
    }
    else {
        // no utf8 transformation, do the array => string step.
        result = utils.transformTo("string", result);
    }

    if (!asUTF8 && !this.options.binary) {
        result = out.utf8encode(result);
    }
    return result;
}
809526
function decodeChunkedArray( bundle, database, size, is_numeric ) {
	var op = bundle.u8[bundle.i8++],
		chunk, chunk_meta = [],	nans, vans=[], i=0, first = true, j=0, l=0,
		splicefn, peekOp, ln=0, type=0, len=0, val=0;

	// Process chunks till PRIM_CHUNK_END
	while (i < size) {
		if (is_numeric) {

			//
			// Use an optimised version of NUM_REPEATED when
			// operating on a numeric array in order to avoid
			// intermediate casting to Array()
			//

			if ((op & 0xF0) === 0x40) { // NUM_REPEATED

				ln = op & 0x01;
				type = (op >> 1) & 0x07;
				len = ln ? bundle.u32[bundle.i32++] : bundle.u16[bundle.i16++];

				// Collect meta
				if (DEBUG) {
					chunk_meta.push({
						type: op,
						len: len
					});
				}

				// Init first value
				if (first) {
					nans = new NUMTYPE_CLASS[ type ]( size );
					first = false;
				}

				// readTypedNum(type)
				switch (type) {
					case 0: val = bundle.u8[bundle.i8++]; break;
					case 1: val = bundle.s8[bundle.i8++]; break;
					case 2: val = bundle.u16[bundle.i16++]; break;
					case 3: val = bundle.s16[bundle.i16++]; break;
					case 4: val = bundle.u32[bundle.i32++]; break;
					case 5: val = bundle.s32[bundle.i32++]; break;
					case 6: val = bundle.f32[bundle.i32++]; break;
					case 7: val = bundle.f64[bundle.i64++]; break;
				}
				nans.fill( val, i, i+len );
				i+= len;

			} else {

				// Collect chunk ops
				chunk = decodeArray( bundle, database, op );
				if (DEBUG) {
					chunk_meta.push({
						type: op,
						len: chunk.length
					});
				}

				// Test for non-arrays
				if (chunk.length === undefined)
					throw new Errors.AssertError('Encountered non-array chunk as part of chunked array!');

				// Init first value
				if (first) {
					nans = new chunk.constructor( size );
					first = false;
				}

				// Test for type mismatch
				if (!(chunk instanceof nans.constructor)) {
					throw new Errors.AssertError("Got is_numeric flag, but chunks are not of the same type (op was "+op+"!");
				}

				// Merge
				nans.set( chunk, i );
				i += chunk.length;

			}

		} else {

			// Collect chunk ops
			chunk = decodeArray( bundle, database, op );
			if (DEBUG) {
				chunk_meta.push({
					type: op,
					len: chunk.length
				});
			}

			// Test for non-arrays
			if (chunk.length === undefined)
				throw new Errors.AssertError('Encountered non-array chunk as part of chunked array!');

			// Init first
			if (first) {
				vans = new Array(size);
				first = false;
			}

			// Merge
			for (j=0, l=chunk.length; j<l; j++, i++) {
				vans[i] = chunk[j];
			}

		}

		// Get next op-code
		if (i < size) {
			op = bundle.u8[bundle.i8++];
		} else {
			break;
		}
	}

	// console.log("-----------");
	// console.log(ans);

	// Return chunked array
	if (is_numeric) {
		return DEBUG
			? __debugMeta( nans, 'array.primitive.chunked', { 'chunks': chunk_meta, 'numeric': true } )
			: nans;
	} else {
		return DEBUG
			? __debugMeta( vans, 'array.primitive.chunked', { 'chunks': chunk_meta, 'numeric': false } )
			: vans;
	}
}