public/wordpress/wp-content/plugins/backupbuddy/destinations/dropbox2/lib/Dropbox/Client.php
/**
     * @param string $path
     *
     * @param WriteMode $writeMode
     *    What to do if there's already a file at the given path (UTF-8).
     *
     * @param resource $inStream
     *    The source of data to upload.
     *
     * @param int|null $numBytes
     *    You can pass in <code>null</code>.  But if you know how many bytes you expect, pass in
     *    that value and this function will do a sanity check at the end to make sure the number of
     *    bytes read from $inStream matches up.
     *
     * @param int $chunkSize
     *
     * @return array
     *    The <a href="https://www.dropbox.com/developers/core/docs#metadata-details>metadata
     *    object</a> for the newly-added file.
     */
@param string $path
@param WriteMode $writeMode
What to do if there's already a file at the given path (UTF-8).

@param resource $inStream
The source of data to upload.

@param int|null $numBytes
You can pass in null.  But if you know how many bytes you expect, pass in
that value and this function will do a sanity check at the end to make sure the number of
bytes read from $inStream matches up.

@param int $chunkSize


@param string $path @param WriteMode $writeMode What to do if there ' s already a file at the given path ( UTF - 8 ) . @param resource $inStream The source of data to upload . @param int|null $numBytes You can pass in null . But if you know how many bytes you expect pass in that value and this function will do a sanity check at the end to make sure the number of bytes read from $inStream matches up . @param int $chunkSize
private function _uploadFileChunked($path, $writeMode, $inStream, $numBytes, $chunkSize)
    {
        Path::checkArg("path", $path);
        WriteMode::checkArg("writeMode", $writeMode);
        Checker::argResource("inStream", $inStream);
        Checker::argNatOrNull("numBytes", $numBytes);
        Checker::argNat("chunkSize", $chunkSize);
        assert($chunkSize > 0);
        $data = self::readFully($inStream, $chunkSize);
        $len = strlen($data);
        $client = $this;
        $uploadId = RequestUtil::runWithRetry(3, function() use ($data, $client) {
            return $client->chunkedUploadStart($data);
        });
        $byteOffset = $len;
        while (!feof($inStream)) {
            $data = self::readFully($inStream, $chunkSize);
            $len = strlen($data);
            while (true) {
                $r = RequestUtil::runWithRetry(3,
                    function() use ($client, $uploadId, $byteOffset, $data) {
                    	\pb_backupbuddy::status( 'details', 'Call chunkedUploadContinue.' );
                        return $client->chunkedUploadContinue($uploadId, $byteOffset, $data);
                    });
                if ($r === true) {  
                    $byteOffset += $len;
                    break;
                }
                if ($r === false) {  
                    throw new Exception_BadResponse("Server forgot our uploadId");
                }
                $serverByteOffset = $r;
                assert($serverByteOffset !== $byteOffset);  
                if ($serverByteOffset < $byteOffset) throw new Exception_BadResponse(
                    "Server is at an ealier byte offset: us=$byteOffset, server=$serverByteOffset");
                $diff = $serverByteOffset - $byteOffset;
                if ($diff > $len) throw new Exception_BadResponse(
                    "Server is more than a chunk ahead: us=$byteOffset, server=$serverByteOffset");
                $byteOffset += $diff;
                if ($diff === $len) break;  
                $data = substr($data, $diff);
            }
        }
        if ($numBytes !== null && $byteOffset !== $numBytes) throw new \InvalidArgumentException(
            "You passed numBytes=$numBytes but the stream had $byteOffset bytes.");
        $metadata = RequestUtil::runWithRetry(3,
            function() use ($client, $uploadId, $path, $writeMode, $byteOffset) {
            	\pb_backupbuddy::status( 'details', 'Call chunkedUploadFinish.' );
                return $client->chunkedUploadFinish($uploadId, $path, $writeMode,$byteOffset);
            });
        return $metadata;
    }
private function _uploadFileChunked ( $ path , $ writeMode , $ inStream , $ numBytes , $ chunkSize ) { Path :: checkArg ( " path " , $ path ) ; WriteMode :: checkArg ( " writeMode " , $ writeMode ) ; Checker :: argResource ( " inStream " , $ inStream ) ; Checker :: argNatOrNull ( " numBytes " , $ numBytes ) ; Checker :: argNat ( " chunkSize " , $ chunkSize ) ; assert ( $ chunkSize > 0 ) ; $ data = self :: readFully ( $ inStream , $ chunkSize ) ; $ len = strlen ( $ data ) ; $ client = $ this ; $ uploadId = RequestUtil :: runWithRetry ( 3 , function ( ) use ( $ data , $ client ) { return $ client -> chunkedUploadStart ( $ data ) ; } ) ; $ byteOffset = $ len ; while ( ! feof ( $ inStream ) ) { $ data = self :: readFully ( $ inStream , $ chunkSize ) ; $ len = strlen ( $ data ) ; while ( true ) { $ r = RequestUtil :: runWithRetry ( 3 , function ( ) use ( $ client , $ uploadId , $ byteOffset , $ data ) { \ pb_backupbuddy :: status ( 'details' , 'Call chunkedUploadContinue.' ) ; return $ client -> chunkedUploadContinue ( $ uploadId , $ byteOffset , $ data ) ; } ) ; if ( $ r === true ) { $ byteOffset += $ len ; break ; } if ( $ r === false ) { throw new Exception_BadResponse ( " Server forgot our uploadId " ) ; } $ serverByteOffset = $ r ; assert ( $ serverByteOffset !== $ byteOffset ) ; if ( $ serverByteOffset < $ byteOffset ) throw new Exception_BadResponse ( " Server is at an ealier byte offset: us= $ byteOffset , server= $ serverByteOffset " ) ; $ diff = $ serverByteOffset - $ byteOffset ; if ( $ diff > $ len ) throw new Exception_BadResponse ( " Server is more than a chunk ahead: us= $ byteOffset , server= $ serverByteOffset " ) ; $ byteOffset += $ diff ; if ( $ diff === $ len ) break ; $ data = substr ( $ data , $ diff ) ; } } if ( $ numBytes !== null && $ byteOffset !== $ numBytes ) throw new \ InvalidArgumentException ( " You passed numBytes= $ numBytes  but the stream had  $ byteOffset  bytes. " ) ; $ metadata = RequestUtil :: runWithRetry ( 3 , function ( ) use ( $ client , $ uploadId , $ path , $ writeMode , $ byteOffset ) { \ pb_backupbuddy :: status ( 'details' , 'Call chunkedUploadFinish.' ) ; return $ client -> chunkedUploadFinish ( $ uploadId , $ path , $ writeMode , $ byteOffset ) ; } ) ; return $ metadata ; }
@param string $path
 @param WriteMode $writeMode
    What to do if there's already a file at the given path (UTF-8).
@param string $path @param WriteMode $writeMode What to do if there ' s already a file at the given path ( UTF - 8 ) .
// NOTE: This function performs 3 retries on every call.  This is maybe not the right // layer to make retry decisions.  It's also awkward because none of the other calls // perform retries. // Chunk got uploaded! // Server didn't recognize our upload ID // This is very unlikely since we're uploading all the chunks in sequence. // Otherwise, the server is at a different byte offset from us. // chunkedUploadContinue ensures this. // An earlier byte offset means the server has lost data we sent earlier. // If the server is past where we think it could possibly be, something went wrong. // The normal case is that the server is a bit further along than us because of a // partially-uploaded chunk.  Finish it off. // If the server is at the end, we're done.