@@ -16,6 +16,10 @@ class Qiniu_Rio_PutExtra
1616 public $ Progresses = null ; // 可选。上传进度:[]BlkputRet
1717 public $ Notify = null ; // 进度通知:func(blkIdx int, blkSize int, ret *BlkputRet)
1818 public $ NotifyErr = null ; // 错误通知:func(blkIdx int, blkSize int, err error)
19+
20+ public function __construct ($ bucket = null ) {
21+ $ this ->Bucket = $ bucket ;
22+ }
1923}
2024
2125// ----------------------------------------------------------
@@ -34,12 +38,19 @@ function Qiniu_Rio_BlockCount($fsize) // => $blockCnt
3438
3539function Qiniu_Rio_Mkblock ($ self , $ host , $ reader , $ size ) // => ($blkputRet, $err)
3640{
37- $ body = fread ($ reader , $ size );
38- if ($ body === false ) {
39- $ err = Qiniu_NewError (0 , 'fread failed ' );
40- return array (null , $ err );
41+ if (is_resource ($ reader )) {
42+ $ body = fread ($ reader , $ size );
43+ if ($ body === false ) {
44+ $ err = Qiniu_NewError (0 , 'fread failed ' );
45+ return array (null , $ err );
46+ }
47+ } else {
48+ list ($ body , $ err ) = $ reader ->Read ($ size );
49+ if ($ err !== null ) {
50+ return array (null , $ err );
51+ }
4152 }
42- if (strlen ($ body ) != $ fsize ) {
53+ if (strlen ($ body ) != $ size ) {
4354 $ err = Qiniu_NewError (0 , 'fread failed: unexpected eof ' );
4455 return array (null , $ err );
4556 }
@@ -58,7 +69,7 @@ function Qiniu_Rio_Mkfile($self, $host, $key, $fsize, $extra) // => ($putRet, $e
5869 }
5970
6071 $ ctxs = array ();
61- for ($ extra ->Progresses as $ prog ) {
72+ foreach ($ extra ->Progresses as $ prog ) {
6273 $ ctxs []= $ prog ['ctx ' ];
6374 }
6475 $ body = implode (', ' , $ ctxs );
@@ -98,8 +109,8 @@ function Qiniu_Rio_Put($upToken, $key, $body, $fsize, $putExtra) // => ($putRet,
98109 $ progresses = array ();
99110 $ host = $ QINIU_UP_HOST ;
100111 $ uploaded = 0 ;
101- while ($ uploaded < $ fsize ) {
102- if ($ uploaded + QINIU_RIO_BLOCK_SIZE < $ fsize ) {
112+ while ($ uploaded < $ fsize ) {
113+ if ($ fsize < $ uploaded + QINIU_RIO_BLOCK_SIZE ) {
103114 $ bsize = $ fsize - $ uploaded ;
104115 } else {
105116 $ bsize = QINIU_RIO_BLOCK_SIZE ;
@@ -110,12 +121,12 @@ function Qiniu_Rio_Put($upToken, $key, $body, $fsize, $putExtra) // => ($putRet,
110121 $ progresses []= $ blkputRet ;
111122 }
112123
124+ $ putExtra ->Progresses = $ progresses ;
113125 return Qiniu_Rio_Mkfile ($ self , $ host , $ key , $ fsize , $ putExtra );
114126}
115127
116128function Qiniu_Rio_PutFile ($ upToken , $ key , $ localFile , $ putExtra ) // => ($putRet, $err)
117129{
118-
119130 $ fp = fopen ($ localFile , 'rb ' );
120131 if ($ fp === false ) {
121132 $ err = Qiniu_NewError (0 , 'fopen failed ' );
0 commit comments