public function unpack2(TreasureData_API_Stream_InputStream $stream, $callback)
 {
     while ($buffer = $stream->readLine()) {
         $result = json_decode($buffer, true);
         call_user_func_array($callback, array($result));
     }
 }
Ejemplo n.º 2
0
 protected function unpackImpl(TreasureData_API_Stream_InputStream $stream, $callable = null)
 {
     $result = array();
     while ($line = $stream->readLine()) {
         $line = trim($line);
         if (empty($line)) {
             continue;
         }
         $columns = explode("\t", $line);
         if ($callable) {
             call_user_func_array($callable, array($columns));
         } else {
             $result[] = $columns;
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 protected function unpackImpl(TreasureData_API_Stream_InputStream $stream, $callable = null)
 {
     $result = array();
     while ($line = $stream->readLine()) {
         $line = trim($line);
         if (empty($line)) {
             continue;
         }
         $args = explode(",", $line);
         $tmp = array();
         foreach ($args as $arg) {
             $tmp[] = trim($arg);
         }
         if ($callable) {
             call_user_func_array($callable, array($tmp));
         } else {
             $result[] = $tmp;
         }
     }
     return $result;
 }
 protected function unpackImpl(TreasureData_API_Stream_InputStream $stream, $callback = null)
 {
     $unpacker = new MessagePackUnpacker();
     $result = array();
     $offset = 0;
     $flag = true;
     $call = false;
     if (is_callable($callback)) {
         $call = true;
         $result = true;
     }
     while (true) {
         if ($flag) {
             $buffer = $stream->read();
             $flag = false;
         }
         if (empty($buffer)) {
             break;
         }
         if ($unpacker->execute($buffer, $offset)) {
             if ($call) {
                 call_user_func_array($callback, array($unpacker->data()));
             } else {
                 $result[] = $unpacker->data();
             }
             $unpacker->reset();
             $buffer = substr($buffer, $offset);
             $offset = 0;
             if (empty($buffer)) {
                 $flag = true;
                 continue;
             }
         }
     }
     return $result;
 }