Buffers bytes into $this->buffer, removing uuencoding headers and footers
and decoding them.
162229
private function fillBuffer($length)
    {
        // 5040 = 63 * 80, seems to be good balance for buffering in benchmarks
        // testing with a simple 'if ($length < x)' and calculating a better
        // size reduces speeds by up to 4x
        while ($this->buffer->getSize() < $length) {
            $read = $this->readToEndOfLine(5040);
            if ($read === false || $read === '') {
                break;
            }
            $this->buffer->write($this->filterAndDecode($read));
        }
    }
1307064
function teardownChunk(chunk, encoding) {
	if (!(chunk instanceof Buffer)) {
		chunk = new Buffer(chunk);
	}
	if (encoding == 'gbk') {
		chunk = iconv.encode(iconv.decode(chunk, 'utf8'), 'gbk');
	}
	return chunk;
}
61064
private static ByteBuffer trim(ByteBuffer buf) {
        if (buf.capacity() <= 4 * buf.remaining()) {
            return buf;
        } else {
            ByteBuffer clone = ByteBuffer.allocate(buf.remaining());
            buf.get(clone.array());
            return clone;
        }
    }
181136
function toBuffer(data, encoding) {
    return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ?
        Buffer.from(data, encoding) : new Buffer(data, encoding);
}
1036437
void cleanup(Http2Stream stream, EmbeddedChannel compressor) {
        if (compressor.finish()) {
            for (;;) {
                final ByteBuf buf = compressor.readOutbound();
                if (buf == null) {
                    break;
                }

                buf.release();
            }
        }
        stream.removeProperty(propertyKey);
    }
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 )

}
840514
function headers(buffer) {
    var head = {};
    if (buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4E &&
        buffer[3] === 0x47 && buffer[4] === 0x0D && buffer[5] === 0x0A &&
        buffer[6] === 0x1A && buffer[7] === 0x0A) {
        head['Content-Type'] = 'image/png';
    } else if (buffer[0] === 0xFF && buffer[1] === 0xD8 &&
        buffer[buffer.length - 2] === 0xFF && buffer[buffer.length - 1] === 0xD9) {
        head['Content-Type'] = 'image/jpeg';
    } else if (buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46 &&
        buffer[3] === 0x38 && (buffer[4] === 0x39 || buffer[4] === 0x37) &&
        buffer[5] === 0x61) {
        head['Content-Type'] = 'image/gif';
    } else if (buffer[0] === 0x52 && buffer[1] === 0x49 && buffer[2] === 0x46 && buffer[3] === 0x46 &&
        buffer[8] === 0x57 && buffer[9] === 0x45 && buffer[10] === 0x42 && buffer[11] === 0x50) {
        head['Content-Type'] = 'image/webp';
    // deflate: recklessly assumes contents are PBF.
    } else if (buffer[0] === 0x78 && buffer[1] === 0x9C) {
        head['Content-Type'] = 'application/x-protobuf';
        head['Content-Encoding'] = 'deflate';
    // gzip: recklessly assumes contents are PBF.
    } else if (buffer[0] === 0x1F && buffer[1] === 0x8B) {
        head['Content-Type'] = 'application/x-protobuf';
        head['Content-Encoding'] = 'gzip';
    }
    return head;
}
805887
public function decodeChunked($buffer, $lb)
    {
        // length := 0
        $length = 0;
        $new = '';

        // read chunk-size, chunk-extension (if any) and CRLF
        // get the position of the linebreak
        $chunkend = strpos($buffer, $lb);
        if ($chunkend == false) {
            $this->debug('no linebreak found in decodeChunked');
            return $new;
        }
        $temp = substr($buffer, 0, $chunkend);
        $chunk_size = hexdec(trim($temp));
        $chunkstart = $chunkend + strlen($lb);
        // while (chunk-size > 0) {
        while ($chunk_size > 0) {
            $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
            $chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size);

            // Just in case we got a broken connection
            if ($chunkend == false) {
                $chunk = substr($buffer, $chunkstart);
                // append chunk-data to entity-body
                $new .= $chunk;
                $length += strlen($chunk);
                break;
            }

            // read chunk-data and CRLF
            $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
            // append chunk-data to entity-body
            $new .= $chunk;
            // length := length + chunk-size
            $length += strlen($chunk);
            // read chunk-size and CRLF
            $chunkstart = $chunkend + strlen($lb);

            $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
            if ($chunkend == false) {
                break; //Just in case we got a broken connection
            }
            $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
            $chunk_size = hexdec(trim($temp));
            $chunkstart = $chunkend;
        }
        return $new;
    }
574846
public function flushOuputBuffer()
    {
        //====================================================================//
        // Read the contents of the output buffer
        $contents = ob_get_contents();
        //====================================================================//
        // Clean (erase) the output buffer and turn off output buffering
        ob_end_clean();
        if ($contents) {
            //====================================================================//
            //  Load Translation File
            Splash::translator()->load('main');
            //====================================================================//
            //  Push Warning to Log
            $this->war('UnexOutputs', $contents);
            $this->war('UnexOutputsMsg');
        }
    }
749147
function __decode_utf8(buffer) {

        var text = "";

        var bytes = new Uint8Array(buffer);
        for (var i=0; i<bytes.length; i++) {

            // Get current byte
            var value = bytes[i];

            // Start new codepoint if nothing yet read
            if (bytes_remaining === 0) {

                // 1 byte (0xxxxxxx)
                if ((value | 0x7F) === 0x7F)
                    text += String.fromCharCode(value);

                // 2 byte (110xxxxx)
                else if ((value | 0x1F) === 0xDF) {
                    codepoint = value & 0x1F;
                    bytes_remaining = 1;
                }

                // 3 byte (1110xxxx)
                else if ((value | 0x0F )=== 0xEF) {
                    codepoint = value & 0x0F;
                    bytes_remaining = 2;
                }

                // 4 byte (11110xxx)
                else if ((value | 0x07) === 0xF7) {
                    codepoint = value & 0x07;
                    bytes_remaining = 3;
                }

                // Invalid byte
                else
                    text += "\uFFFD";

            }

            // Continue existing codepoint (10xxxxxx)
            else if ((value | 0x3F) === 0xBF) {

                codepoint = (codepoint << 6) | (value & 0x3F);
                bytes_remaining--;

                // Write codepoint if finished
                if (bytes_remaining === 0)
                    text += String.fromCharCode(codepoint);

            }

            // Invalid byte
            else {
                bytes_remaining = 0;
                text += "\uFFFD";
            }

        }

        return text;

    }
1190948
public function decompress($buffer)
    {
        $dictionary       = array();
        $data             = $this->multibyteStringSplit($buffer);

        $currentCharacter = $data[0];
        $oldPhrase        = $currentCharacter;
        $out              = array($currentCharacter);
        $code             = 256;
        $countData        = count($data);

        for ($i = 1; $i < $countData; ++$i) {
            $currCode = $this->uniord($data[$i]);

            if ($currCode < 256) {
                $phrase = $data[$i];

            } else {
                $phrase = isset($dictionary[$currCode]) ? $dictionary[$currCode] : $oldPhrase.$currentCharacter;
            }

            $out[]             = $phrase;
            $currentCharacter  = $phrase[0];
            $dictionary[$code] = $oldPhrase . $currentCharacter;

            $code++;

            $oldPhrase = $phrase;
        }

        return implode('', $out);
    }
538026
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.numberOfLinks = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.deletePending = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        this.directory = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        return bufferIndex - start;
    }
168414
private function parse() {
		// remove first line
		$lead = strstr($this->data, "\n", true);
		$this->data = substr(strstr($this->data, "\n"), 1);

		// parse first line
		$pieces = explode(" ", $lead);
		$this->httpVersion = (Integer)trim(substr(strstr($pieces[0], "/"), 1));
		$this->code = (Integer)trim($pieces[1]);

		// split into head and body
		$head = strstr($this->data, "\r\n\r\n", true);
		$this->body = substr(strstr($this->data, "\r\n\r\n"), 4);

		// parse headers
		foreach(explode("\n", $head) as $line) {
			$this->headers[strtolower(strstr($line, ":", true))] = trim(substr(strstr($line, ":"), 2));
		}

		// fix content type header, move charset to its own if present
		if(isset($this->headers["content-type"]) && strpos($this->headers["content-type"], ";")) {
			$this->headers["content-type"] = strtok($this->headers["content-type"], ";");
			if(!isset($this->headers["charset"])) $this->headers["charset"] = substr(strstr(strtok(";"), "="), 1);
		}

		// decode if chunked
		if($this->decodeChunked && isset($this->headers["transfer-encoding"]) && strtolower($this->headers["transfer-encoding"]) == "chunked") {
			for($decoded = ""; !empty($this->body); $this->body = trim($this->body)) {
				$position = strpos($this->body, "\r\n");
				$length = hexdec(substr($this->body, 0, $position));
				$decoded .= substr($this->body, $position + 2, $length);
				$this->body = substr($this->body, $position + 2 + $length);
			}

			$this->body = $decoded;
			unset($decoded);
		}

		// parse body as json if in json mode
		if($this->json && strtolower($this->headers["content-type"]) == "application/json") {
			$json = json_decode($this->body);
			if(json_last_error() == JSON_ERROR_NONE) $this->body = $json;
		}

		// cleanup
		unset($this->data, $head, $lead);

		
	}
421154
protected function processInputBuffer()
    {
        //$this->logger->debug('Trying to process buffer of HttpClient');

        if ($this->request === null) { //New request
            if (isset($this->inputBuffer[HttpRequest::MAX_HEADER_LENGTH])) { //Much faster than strlen ;)
                $this->logger->warning("Client $this sent headers larger than " . HttpRequest::MAX_HEADER_LENGTH . ' bytes');
                $this->inputBuffer = '';
                throw new HttpException('Server refused request exceeding ' . HttpRequest::MAX_HEADER_LENGTH . ' bytes',
                    HttpCode::REQUEST_HEADER_FIELDS_TOO_LARGE, array(), true);
            }

            $headersBreakpoint = strpos($this->inputBuffer, "\r\n\r\n"); //Try to find headers breakpoint
            if ($headersBreakpoint === false) { //Not found, nothing to do
                //$this->logger->debug('Buffer doesn't contain full HTTP headers [yet]');
                return;
            }

            //TODO: Refactor to 2x substr (based on $headersBreakpoint) - it's ~5% faster [but it need to be changed along with payloads support]
            list($headers, $this->inputBuffer) = explode("\r\n\r\n", $this->inputBuffer, 2);
            //$this->logger->debug('Got HTTP headers, creating HttpRequest...');
            $this->request = new HttpRequest($headers, $this->logger);
        }
        //In future: else { add data to already created request }
    }
971343
function decode(pem) {
  if (Buffer.isBuffer(pem)) {
    pem = pem.toString('ascii')
  }

  const lines = pem.trim().split('\n')

  if (lines.length < 3) {
    throw new Error('Invalid PEM data.')
  }

  const match = header.exec(lines[0])

  if (match === null) {
    throw new Error('Invalid label.')
  }

  const label = match[1]
  let i = 1

  for (; i < lines.length; ++i) {
    if (lines[i].startsWith(after)) {
      break
    }
  }

  const footer = new RegExp(`^${after} ${label}${endline}\r?\n?$`)

  if (footer.exec(lines[i]) === null) {
    throw new Error('Invalid end of file.')
  }

  const body = lines.slice(1, i).join('\n').replace(/\r?\n/g, '')
  return Buffer.from(body, 'base64')
}
270745
function bnToBuffer(trimOrSize) {
    var res = new Buffer(this.toByteArray());
    if (trimOrSize === true && res[0] === 0) {
        res = res.slice(1);
    } else if (_.isNumber(trimOrSize)) {
        if (res.length > trimOrSize) {
            for (var i = 0; i < res.length - trimOrSize; i++) {
                if (res[i] !== 0) {
                    return null;
                }
            }
            return res.slice(res.length - trimOrSize);
        } else if (res.length < trimOrSize) {
            var padded = new Buffer(trimOrSize);
            padded.fill(0, 0, trimOrSize - res.length);
            res.copy(padded, trimOrSize - res.length);
            return padded;
        }
    }
    return res;
}
496821
public int decode(final InputStream stream, final ByteBuffer buffer) throws IOException {
        while (buffer.remaining() >= 64) {
            int val = stream.read();
            if (val < 0) {
                break; // EOF
            }

            if ((val & COMPRESSED_RUN_MASK) == COMPRESSED_RUN_MASK) {
                int count = val & ~COMPRESSED_RUN_MASK;

                int pixel = stream.read();
                if (pixel < 0) {
                    break; // EOF
                }

                for (int i = 0; i < count; i++) {
                    buffer.put((byte) pixel);
                }
            }
            else {
                buffer.put((byte) val);
            }
        }

        return buffer.position();
    }