3 namespace PhpXmlRpc\Helper;
8 * decode a string that is encoded w/ "chunked" transfer encoding
9 * as defined in rfc2068 par. 19.4.6
10 * code shamelessly stolen from nusoap library by Dietrich Ayala
12 * @param string $buffer the string to be decoded
15 public static function decode_chunked($buffer)
21 // read chunk-size, chunk-extension (if any) and crlf
22 // get the position of the linebreak
23 $chunkend = strpos($buffer,"\r\n") + 2;
24 $temp = substr($buffer,0,$chunkend);
25 $chunk_size = hexdec( trim($temp) );
26 $chunkstart = $chunkend;
27 while($chunk_size > 0)
29 $chunkend = strpos($buffer, "\r\n", $chunkstart + $chunk_size);
31 // just in case we got a broken connection
32 if($chunkend == false)
34 $chunk = substr($buffer,$chunkstart);
35 // append chunk-data to entity-body
37 $length += strlen($chunk);
41 // read chunk-data and crlf
42 $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
43 // append chunk-data to entity-body
45 // length := length + chunk-size
46 $length += strlen($chunk);
47 // read chunk-size and crlf
48 $chunkstart = $chunkend + 2;
50 $chunkend = strpos($buffer,"\r\n",$chunkstart)+2;
51 if($chunkend == false)
53 break; //just in case we got a broken connection
55 $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
56 $chunk_size = hexdec( trim($temp) );
57 $chunkstart = $chunkend;