Skip to content

Commit 02c52b3

Browse files
committed
onret(ret) -> onret(err, ret)
1 parent 6c0a3e9 commit 02c52b3

File tree

12 files changed

+266
-230
lines changed

12 files changed

+266
-230
lines changed

docs/README.gist.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,14 @@ PutExtra是上传时的可选信息,默认为null
279279

280280
#### 批量操作
281281

282-
当您需要一次性进行多个操作时, 可以使用批量操作。
282+
当您需要一次性进行多个操作时, 可以使用批量操作。
283+
批量操作的几个函数中,当返回值`err``null`的时候,有两种情况:
284+
285+
1. 批量操作的所有操作都成功
286+
2. 批量操作仅仅部分成功
287+
288+
因此在返回成功的时候还需要检查各个子项目的返回值(详细见各个示例)。
289+
注意:批量操作不是对单个文件操作的包装,而是有独立的接口。
283290

284291
#### 批量获取文件信息
285292

docs/README.md

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ function uploadBuf(body, key, uptoken) {
221221
//extra.crc32 = crc32;
222222
//extra.checkCrc = checkCrc;
223223
224-
io.put(uptoken, key, body, extra, function(ret) {
225-
if(ret.code === 200) {
224+
io.put(uptoken, key, body, extra, function(err, ret) {
225+
if (!err) {
226226
// 上传成功, 处理返回值
227-
// ret.data.key & ret.data.hash
227+
console.log(ret.key, ret.hash);
228+
// ret.key & ret.hash
228229
} else {
229230
// 上传失败, 处理返回代码
230-
// ret.code
231+
console.log(err)
231232
// http://docs.qiniu.com/api/put.html#error-code
232233
}
233234
});
@@ -244,13 +245,14 @@ function uploadFile(localFile, key, uptoken) {
244245
//extra.crc32 = crc32;
245246
//extra.checkCrc = checkCrc;
246247
247-
io.putFile(uptoken, key, localFile, extra, function(ret) {
248-
if(ret.code === 200) {
248+
io.putFile(uptoken, key, localFile, extra, function(err, ret) {
249+
if(!err) {
249250
// 上传成功, 处理返回值
250-
// ret.data.key & ret.data.hash
251+
console.log(ret.key, ret.hash);
252+
// ret.key & ret.hash
251253
} else {
252254
// 上传失败, 处理返回代码
253-
// ret.code
255+
console.log(err);
254256
// http://docs.qiniu.com/api/put.html#error-code
255257
}
256258
});
@@ -318,12 +320,12 @@ qiniu.conf.SECRET_KEY = '<Your Secret Key>';
318320

319321
```{javascript}
320322
var client = new qiniu.rs.Client();
321-
client.stat(bucketName, key, function(ret) {
322-
if (ret.code === 200) {
323-
// process
324-
// ret.data has keys (hash, fsize, putTime, mimeType)
323+
client.stat(bucketName, key, function(err, ret) {
324+
if (!err) {
325+
// ok
326+
// ret has keys (hash, fsize, putTime, mimeType)
325327
} else {
326-
// something error, process ret.code
328+
console.log(err);
327329
// http://docs.qiniu.com/api/file-handle.html#error-code
328330
}
329331
});
@@ -335,11 +337,11 @@ client.stat(bucketName, key, function(ret) {
335337

336338
```{javascript}
337339
var client = new qiniu.rs.Client();
338-
client.remove(bucketName, key, function(ret) {
339-
if (ret.code === 200) {
340+
client.remove(bucketName, key, function(err, ret) {
341+
if (!err) {
340342
// ok
341343
} else {
342-
// something error, process ret.code
344+
console.log(err);
343345
// http://docs.qiniu.com/api/file-handle.html#error-code
344346
}
345347
})
@@ -351,23 +353,23 @@ client.remove(bucketName, key, function(ret) {
351353

352354
```{javascript}
353355
var client = new qiniu.rs.Client();
354-
client.copy(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
355-
if (ret.code === 200) {
356+
client.copy(bucketSrc, keySrc, bucketDest, keyDest, function(err, ret) {
357+
if (!err) {
356358
// ok
357359
} else {
358-
// something error, process ret.code
360+
console.log(err);
359361
// http://docs.qiniu.com/api/file-handle.html#error-code
360362
}
361363
});
362364
```
363365

364366
```{javascript}
365367
var client = new qiniu.rs.Client();
366-
client.move(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
367-
if (ret.code === 200) {
368+
client.move(bucketSrc, keySrc, bucketDest, keyDest, function(err, ret) {
369+
if (!err) {
368370
// ok
369371
} else {
370-
// something error, process ret.code
372+
console.log(err);
371373
// http://docs.qiniu.com/api/file-handle.html#error-code
372374
}
373375
});
@@ -377,7 +379,14 @@ client.move(bucketSrc, keySrc, bucketDestm keyDest, function(ret) {
377379

378380
#### 批量操作
379381

380-
当您需要一次性进行多个操作时, 可以使用批量操作。
382+
当您需要一次性进行多个操作时, 可以使用批量操作。
383+
批量操作的几个函数中,当返回值`err``null`的时候,有两种情况:
384+
385+
1. 批量操作的所有操作都成功
386+
2. 批量操作仅仅部分成功
387+
388+
因此在返回成功的时候还需要检查各个子项目的返回值(详细见各个示例)。
389+
注意:批量操作不是对单个文件操作的包装,而是有独立的接口。
381390

382391
#### 批量获取文件信息
383392

@@ -386,13 +395,20 @@ var path0 = new qiniu.rs.EntryPath(bucketName, key0);
386395
var path1 = new qiniu.rs.EntryPath(bucketName, key1);
387396
var path2 = new qiniu.rs.EntryPath(bucketName, key2);
388397
var client = new qiniu.rs.Client();
389-
client.batchStat([path0, path1, path2], function(ret) {
390-
if (ret.code === 200) {
391-
// ok, parse ret.data
392-
// each item in ret.data has keys (code, data)
393-
// ret.data[i].data has keys (hash, fsize, putTime, mimeType)
398+
399+
client.batchStat([path0, path1, path2], function(err, ret) {
400+
if (!err) {
401+
for (i in ret) {
402+
if (ret[i].code === 200) {
403+
//ok, ret[i].data has keys (hash, fsize, putTime, mimeType)
404+
} else {
405+
// parse error code
406+
console.log(ret[i].code, ret[i].data);
407+
// http://docs.qiniu.com/api/file-handle.html#error-code
408+
}
409+
}
394410
} else {
395-
// something error, process ret.code
411+
console.log(err);
396412
// http://docs.qiniu.com/api/file-handle.html#error-code
397413
}
398414
});
@@ -405,15 +421,24 @@ var pathSrc0 = new qiniu.rs.EntryPath(bucketName, key0);
405421
var pathDest0 = new qiniu.rs.EntryPath(bucketName, key1);
406422
var pathSrc1 = new qiniu.rs.EntryPath(bucketName, key2);
407423
var pathDest1 = new qiniu.rs.EntryPath(bucketName, key3);
424+
408425
var pair0 = new qiniu.rs.EntryPathPair(pathSrc0, pathDest0);
409426
var pair1 = new qiniu.rs.EntryPathPair(pathSrc1, pathDest1);
427+
410428
var client = new qiniu.rs.Client();
411429
412-
client.batchCopy([pair0, pair1], function(ret) {
413-
if (ret.code === 200) {
414-
// ok
430+
client.batchCopy([pair0, pair1], function(err, ret) {
431+
if (!err) {
432+
for (i in ret) {
433+
if (ret[i].code !== 200) {
434+
// parse error code
435+
console.log(ret[i].code, ret[i].data);
436+
// http://docs.qiniu.com/api/file-handle.html#error-code
437+
}
438+
}
439+
415440
} else {
416-
// something error, process ret.code
441+
console.log(err);
417442
// http://docs.qiniu.com/api/file-handle.html#error-code
418443
}
419444
});
@@ -426,15 +451,23 @@ var pathSrc0 = new qiniu.rs.EntryPath(bucketName, key0);
426451
var pathDest0 = new qiniu.rs.EntryPath(bucketName, key1);
427452
var pathSrc1 = new qiniu.rs.EntryPath(bucketName, key2);
428453
var pathDest1 = new qiniu.rs.EntryPath(bucketName, key3);
454+
429455
var pair0 = new qiniu.rs.EntryPathPair(pathSrc0, pathDest0);
430456
var pair1 = new qiniu.rs.EntryPathPair(pathSrc1, pathDest1);
457+
431458
var client = new qiniu.rs.Client();
432459
433-
client.batchMove([pair0, pair1], function(ret) {
434-
if (ret.code === 200) {
435-
// ok
460+
client.batchMove([pair0, pair1], function(err, ret) {
461+
if (!err) {
462+
for (i in ret) {
463+
if (ret[i] !== 200) {
464+
// parse error code
465+
console.log(ret[i].code, ret[i].data);
466+
// http://docs.qiniu.com/api/file-handle.html#error-code
467+
}
468+
}
436469
} else {
437-
// something error, process ret.code
470+
console.log(err);
438471
// http://docs.qiniu.com/api/file-handle.html#error-code
439472
}
440473
});
@@ -446,13 +479,20 @@ client.batchMove([pair0, pair1], function(ret) {
446479
var path0 = new qiniu.rs.EntryPath(bucketName, key0);
447480
var path1 = new qiniu.rs.EntryPath(bucketName, key1);
448481
var path2 = new qiniu.rs.EntryPath(bucketName, key2);
482+
449483
var client = new qiniu.rs.Client();
450484
451-
client.batchDelete([path0, path1, path2], function(ret) {
452-
if (ret.code === 200) {
453-
// ok
485+
client.batchDelete([path0, path1, path2], function(err, ret) {
486+
if (!err) {
487+
for (i in ret) {
488+
if (ret[i].code !== 200) {
489+
// parse error code
490+
console.log(ret[i].code, ret[i].data);
491+
// http://docs.qiniu.com/api/file-handle.html#error-code
492+
}
493+
}
454494
} else {
455-
// something error, process ret.code
495+
console.log(err);
456496
// http://docs.qiniu.com/api/file-handle.html#error-code
457497
}
458498
});
@@ -470,11 +510,11 @@ client.batchDelete([path0, path1, path2], function(ret) {
470510
qiniu.conf.ACCESS_KEY = '<Your Access Key>';
471511
qiniu.conf.SECRET_KEY = '<Your Secret Key>';
472512
473-
qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(ret) {
474-
if(ret.code === 200) {
513+
qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(err, ret) {
514+
if (!err) {
475515
// process ret.data.marker & ret.data.items
476516
} else {
477-
// something error, see ret.code according to
517+
console.log(err)
478518
// http://docs.qiniu.com/api/file-handle.html#list
479519
}
480520
});

docs/gist/client.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ function uploadFile(localFile, key, uptoken) {
88
//extra.crc32 = crc32;
99
//extra.checkCrc = checkCrc;
1010

11-
io.putFile(uptoken, key, localFile, extra, function(ret) {
12-
if(ret.code === 200) {
11+
io.putFile(uptoken, key, localFile, extra, function(err, ret) {
12+
if(!err) {
1313
// 上传成功, 处理返回值
14-
// ret.data.key & ret.data.hash
14+
console.log(ret.key, ret.hash);
15+
// ret.key & ret.hash
1516
} else {
1617
// 上传失败, 处理返回代码
17-
// ret.code
18+
console.log(err);
1819
// http://docs.qiniu.com/api/put.html#error-code
1920
}
2021
});
@@ -29,13 +30,14 @@ function uploadBuf(body, key, uptoken) {
2930
//extra.crc32 = crc32;
3031
//extra.checkCrc = checkCrc;
3132

32-
io.put(uptoken, key, body, extra, function(ret) {
33-
if(ret.code === 200) {
33+
io.put(uptoken, key, body, extra, function(err, ret) {
34+
if (!err) {
3435
// 上传成功, 处理返回值
35-
// ret.data.key & ret.data.hash
36+
console.log(ret.key, ret.hash);
37+
// ret.key & ret.hash
3638
} else {
3739
// 上传失败, 处理返回代码
38-
// ret.code
40+
console.log(err)
3941
// http://docs.qiniu.com/api/put.html#error-code
4042
}
4143
});

0 commit comments

Comments
 (0)