OSS\Http\RequestCore::streaming_read_callback PHP Method

streaming_read_callback() public method

A callback function that is invoked by cURL for streaming up.
public streaming_read_callback ( resource $curl_handle, resource $file_handle, integer $length ) : binary
$curl_handle resource (Required) The cURL handle for the request.
$file_handle resource (Required) The open file handle resource.
$length integer (Required) The maximum number of bytes to read.
return binary Binary data from a stream.
    public function streaming_read_callback($curl_handle, $file_handle, $length)
    {
        // Once we've sent as much as we're supposed to send...
        if ($this->read_stream_read >= $this->read_stream_size) {
            // Send EOF
            return '';
        }
        // If we're at the beginning of an upload and need to seek...
        if ($this->read_stream_read == 0 && isset($this->seek_position) && $this->seek_position !== ftell($this->read_stream)) {
            if (fseek($this->read_stream, $this->seek_position) !== 0) {
                throw new RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
            }
        }
        $read = fread($this->read_stream, min($this->read_stream_size - $this->read_stream_read, $length));
        // Remaining upload data or cURL's requested chunk size
        $this->read_stream_read += strlen($read);
        $out = $read === false ? '' : $read;
        // Execute callback function
        if ($this->registered_streaming_read_callback) {
            call_user_func($this->registered_streaming_read_callback, $curl_handle, $file_handle, $out);
        }
        return $out;
    }