function decodeUtf8(bytes) {
  let offset = 0;
  const codePoints = [];
  while (offset < bytes.byteLength) {
    const c = bytes.getUint8(offset++);
    if (c < 0x80) {  // Regular 7-bit ASCII.
      codePoints.push(c);
    } else if (c < 0xC0) {
      // UTF-8 continuation mark. We are out of sync. This
      // might happen if we attempted to read a character
      // with more than four bytes.
      continue;
    } else if (c < 0xE0) {  // UTF-8 with two bytes.
      const c2 = bytes.getUint8(offset++);
      codePoints.push(((c & 0x1F) << 6) | (c2 & 0x3F));
    } else if (c < 0xF0) {  // UTF-8 with three bytes.
      const c2 = bytes.getUint8(offset++);
      const c3 = bytes.getUint8(offset++);
      codePoints.push(((c & 0xF) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
    } else if (c < 0xF8) {  // UTF-8 with 4 bytes.
      const c2 = bytes.getUint8(offset++);
      const c3 = bytes.getUint8(offset++);
      const c4 = bytes.getUint8(offset++);
      // Characters written on 4 bytes have 21 bits for a codepoint.
      // We can't fit that on 16bit characters, so we use surrogates.
      let codepoint = ((c & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F);
      codePoints.push(codepoint);
    }
  }
  return codePointsToString(codePoints);
}
/**
 * Produces a String from a DataView into UTF-8 bytes.
 *
 * @param {DataView} bytes A view into an array of UTF-8 bytes to convert to a String.
 */
Produces a String from a DataView into UTF-8 bytes.
@param {DataView} bytes A view into an array of UTF-8 bytes to convert to a String.
Produces a String from a DataView into UTF - 8 bytes . @param { DataView } bytes A view into an array of UTF - 8 bytes to convert to a String .
function decodeUtf8(bytes) {
  let offset = 0;
  const codePoints = [];
  while (offset < bytes.byteLength) {
    const c = bytes.getUint8(offset++);
    if (c < 0x80) {  
      codePoints.push(c);
    } else if (c < 0xC0) {
      continue;
    } else if (c < 0xE0) {  
      const c2 = bytes.getUint8(offset++);
      codePoints.push(((c & 0x1F) << 6) | (c2 & 0x3F));
    } else if (c < 0xF0) {  
      const c2 = bytes.getUint8(offset++);
      const c3 = bytes.getUint8(offset++);
      codePoints.push(((c & 0xF) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
    } else if (c < 0xF8) {  
      const c2 = bytes.getUint8(offset++);
      const c3 = bytes.getUint8(offset++);
      const c4 = bytes.getUint8(offset++);
      let codepoint = ((c & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F);
      codePoints.push(codepoint);
    }
  }
  return codePointsToString(codePoints);
}
function decodeUtf8 ( bytes ) { let offset = 0 ; const codePoints = [ ] ; while ( offset < bytes . byteLength ) { const c = bytes . getUint8 ( offset ++ ) ; if ( c < 0x80 ) { codePoints . push ( c ) ; } else if ( c < 0xC0 ) { continue ; } else if ( c < 0xE0 ) { const c2 = bytes . getUint8 ( offset ++ ) ; codePoints . push ( ( ( c & 0x1F ) << 6 ) | ( c2 & 0x3F ) ) ; } else if ( c < 0xF0 ) { const c2 = bytes . getUint8 ( offset ++ ) ; const c3 = bytes . getUint8 ( offset ++ ) ; codePoints . push ( ( ( c & 0xF ) << 12 ) | ( ( c2 & 0x3F ) << 6 ) | ( c3 & 0x3F ) ) ; } else if ( c < 0xF8 ) { const c2 = bytes . getUint8 ( offset ++ ) ; const c3 = bytes . getUint8 ( offset ++ ) ; const c4 = bytes . getUint8 ( offset ++ ) ; let codepoint = ( ( c & 0x07 ) << 18 ) | ( ( c2 & 0x3F ) << 12 ) | ( ( c3 & 0x3F ) << 6 ) | ( c4 & 0x3F ) ; codePoints . push ( codepoint ) ; } } return codePointsToString ( codePoints ) ; }
Produces a String from a DataView into UTF-8 bytes.
Produces a String from a DataView into UTF - 8 bytes .
// Regular 7-bit ASCII. // UTF-8 continuation mark. We are out of sync. This // might happen if we attempted to read a character // with more than four bytes. // UTF-8 with two bytes. // UTF-8 with three bytes. // UTF-8 with 4 bytes. // Characters written on 4 bytes have 21 bits for a codepoint. // We can't fit that on 16bit characters, so we use surrogates.