Skip to content

Commit 0f4e535

Browse files
authored
Merge branch 'master' into tagging-api-ts-migrate
2 parents c69df52 + 51cf376 commit 0f4e535

File tree

11 files changed

+305
-462
lines changed

11 files changed

+305
-462
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ The full API Reference is available here.
190190
#### Full Examples : File Object Operations
191191

192192
- [fput-object.js](https://github.com/minio/minio-js/blob/master/examples/fput-object.js)
193-
- [fget-object.js](https://github.com/minio/minio-js/blob/master/examples/fget-object.js)
193+
- [fget-object.mjs](https://github.com/minio/minio-js/blob/master/examples/fget-object.mjs)
194194

195195
#### Full Examples : Object Operations
196196

197197
- [put-object.js](https://github.com/minio/minio-js/blob/master/examples/put-object.js)
198-
- [get-object.js](https://github.com/minio/minio-js/blob/master/examples/get-object.js)
198+
- [get-object.mjs](https://github.com/minio/minio-js/blob/master/examples/get-object.mjs)
199199
- [copy-object.js](https://github.com/minio/minio-js/blob/master/examples/copy-object.js)
200-
- [get-partialobject.js](https://github.com/minio/minio-js/blob/master/examples/get-partialobject.js)
200+
- [get-partialobject.mjs](https://github.com/minio/minio-js/blob/master/examples/get-partialobject.mjs)
201201
- [remove-object.js](https://github.com/minio/minio-js/blob/master/examples/remove-object.js)
202202
- [remove-incomplete-upload.js](https://github.com/minio/minio-js/blob/master/examples/remove-incomplete-upload.js)
203203
- [stat-object.mjs](https://github.com/minio/minio-js/blob/master/examples/stat-object.mjs)

README_zh_CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ mc ls play/europetrip/
161161

162162
#### 完整示例 : 操作文件对象
163163
* [fput-object.js](https://github.com/minio/minio-js/blob/master/examples/fput-object.js)
164-
* [fget-object.js](https://github.com/minio/minio-js/blob/master/examples/fget-object.js)
164+
* [fget-object.mjs](https://github.com/minio/minio-js/blob/master/examples/fget-object.mjs)
165165

166166
#### 完整示例 : 操作对象
167167
* [put-object.js](https://github.com/minio/minio-js/blob/master/examples/put-object.js)
168-
* [get-object.js](https://github.com/minio/minio-js/blob/master/examples/get-object.js)
168+
* [get-object.mjs](https://github.com/minio/minio-js/blob/master/examples/get-object.mjs)
169169
* [copy-object.js](https://github.com/minio/minio-js/blob/master/examples/copy-object.js)
170-
* [get-partialobject.js](https://github.com/minio/minio-js/blob/master/examples/get-partialobject.js)
170+
* [get-partialobject.mjs](https://github.com/minio/minio-js/blob/master/examples/get-partialobject.mjs)
171171
* [remove-object.js](https://github.com/minio/minio-js/blob/master/examples/remove-object.js)
172172
* [remove-incomplete-upload.js](https://github.com/minio/minio-js/blob/master/examples/remove-incomplete-upload.js)
173173
* [stat-object.mjs](https://github.com/minio/minio-js/blob/master/examples/stat-object.mjs)

docs/API.md

Lines changed: 52 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -861,42 +861,37 @@ s3Client.removeBucketEncryption('my-bucketname', function (err) {
861861

862862
<a name="getObject"></a>
863863

864-
### getObject(bucketName, objectName, getOpts[, callback])
864+
### getObject(bucketName, objectName, getOpts)
865865

866866
Downloads an object as a stream.
867867

868868
**Parameters**
869869

870-
| Param | Type | Description |
871-
| ----------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
872-
| `bucketName` | _string_ | Name of the bucket. |
873-
| `objectName` | _string_ | Name of the object. |
874-
| `getOpts` | _object_ | Version of the object in the form `{versionId:"my-versionId"}`. Default is `{}`. (optional) |
875-
| `callback(err, stream)` | _function_ | Callback is called with `err` in case of error. `stream` is the object content stream. If no callback is passed, a `Promise` is returned. |
870+
| Param | Type | Description |
871+
| ------------ | -------- | ------------------------------------------------------------------------------------------- |
872+
| `bucketName` | _string_ | Name of the bucket. |
873+
| `objectName` | _string_ | Name of the object. |
874+
| `getOpts` | _object_ | Version of the object in the form `{versionId:"my-versionId"}`. Default is `{}`. (optional) |
876875

877876
**Return Value**
878877

879-
| Param | Type | Description |
880-
| -------- | -------- | ----------------------------------- |
881-
| `stream` | _Stream_ | Stream emitting the object content. |
878+
| Param | Type | Description |
879+
| -------- | ----------------- | ----------------------------------- |
880+
| `stream` | `stream.Readable` | Stream emitting the object content. |
882881

883882
**Example**
884883

885884
```js
886885
let size = 0
887-
minioClient.getObject('mybucket', 'photo.jpg', function (err, dataStream) {
888-
if (err) {
889-
return console.log(err)
890-
}
891-
dataStream.on('data', function (chunk) {
892-
size += chunk.length
893-
})
894-
dataStream.on('end', function () {
895-
console.log('End. Total size = ' + size)
896-
})
897-
dataStream.on('error', function (err) {
898-
console.log(err)
899-
})
886+
const dataStream = await minioClient.getObject('mybucket', 'photo.jpg')
887+
dataStream.on('data', function (chunk) {
888+
size += chunk.length
889+
})
890+
dataStream.on('end', function () {
891+
console.log('End. Total size = ' + size)
892+
})
893+
dataStream.on('error', function (err) {
894+
console.log(err)
900895
})
901896
```
902897

@@ -906,19 +901,15 @@ Get a specific object version.
906901

907902
```js
908903
let size = 0
909-
minioClient.getObject('mybucket', 'photo.jpg', { versionId: 'my-versionId' }, function (err, dataStream) {
910-
if (err) {
911-
return console.log(err)
912-
}
913-
dataStream.on('data', function (chunk) {
914-
size += chunk.length
915-
})
916-
dataStream.on('end', function () {
917-
console.log('End. Total size = ' + size)
918-
})
919-
dataStream.on('error', function (err) {
920-
console.log(err)
921-
})
904+
const dataStream = await minioClient.getObject('mybucket', 'photo.jpg', { versionId: 'my-versionId' })
905+
dataStream.on('data', function (chunk) {
906+
size += chunk.length
907+
})
908+
dataStream.on('end', function () {
909+
console.log('End. Total size = ' + size)
910+
})
911+
dataStream.on('error', function (err) {
912+
console.log(err)
922913
})
923914
```
924915

@@ -950,19 +941,15 @@ Downloads the specified range bytes of an object as a stream.
950941
```js
951942
let size = 0
952943
// reads 30 bytes from the offset 10.
953-
minioClient.getPartialObject('mybucket', 'photo.jpg', 10, 30, function (err, dataStream) {
954-
if (err) {
955-
return console.log(err)
956-
}
957-
dataStream.on('data', function (chunk) {
958-
size += chunk.length
959-
})
960-
dataStream.on('end', function () {
961-
console.log('End. Total size = ' + size)
962-
})
963-
dataStream.on('error', function (err) {
964-
console.log(err)
965-
})
944+
const dataStream = await minioClient.getPartialObject('mybucket', 'photo.jpg', 10, 30)
945+
dataStream.on('data', function (chunk) {
946+
size += chunk.length
947+
})
948+
dataStream.on('end', function () {
949+
console.log('End. Total size = ' + size)
950+
})
951+
dataStream.on('error', function (err) {
952+
console.log(err)
966953
})
967954
```
968955

@@ -972,27 +959,16 @@ To get a specific version of an object
972959
```js
973960
const versionedObjSize = 0
974961
// reads 30 bytes from the offset 10.
975-
minioClient.getPartialObject(
976-
'mybucket',
977-
'photo.jpg',
978-
10,
979-
30,
980-
{ versionId: 'my-versionId' },
981-
function (err, dataStream) {
982-
if (err) {
983-
return console.log(err)
984-
}
985-
dataStream.on('data', function (chunk) {
986-
versionedObjSize += chunk.length
987-
})
988-
dataStream.on('end', function () {
989-
console.log('End. Total size = ' + versionedObjSize)
990-
})
991-
dataStream.on('error', function (err) {
992-
console.log(err)
993-
})
994-
},
995-
)
962+
const dataStream = await minioClient.getPartialObject('mybucket', 'photo.jpg', 10, 30, { versionId: 'my-versionId' })
963+
dataStream.on('data', function (chunk) {
964+
versionedObjSize += chunk.length
965+
})
966+
dataStream.on('end', function () {
967+
console.log('End. Total size = ' + versionedObjSize)
968+
})
969+
dataStream.on('error', function (err) {
970+
console.log(err)
971+
})
996972
```
997973

998974
<a name="fGetObject"></a>
@@ -1981,26 +1957,23 @@ listener.on('notification', function (record) {
19811957

19821958
<a name="getBucketPolicy"></a>
19831959

1984-
### getBucketPolicy(bucketName [, callback])
1960+
### async getBucketPolicy(bucketName: string): Promise<string>
19851961

19861962
Get the bucket policy associated with the specified bucket. If `objectPrefix`
19871963
is not empty, the bucket policy will be filtered based on object permissions
19881964
as well.
19891965

19901966
**Parameters**
19911967

1992-
| Param | Type | Description |
1993-
| ----------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1994-
| `bucketName` | _string_ | Name of the bucket |
1995-
| `callback(err, policy)` | _function_ | Callback function is called with non `null` err value in case of error. `policy` is [bucket policy](https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html). If no callback is passed, a `Promise` is returned. |
1968+
| Param | Type | Description |
1969+
| ------------ | -------- | ------------------ |
1970+
| `bucketName` | _string_ | Name of the bucket |
19961971

19971972
```js
19981973
// Retrieve bucket policy of 'my-bucketname'
1999-
minioClient.getBucketPolicy('my-bucketname', function (err, policy) {
2000-
if (err) throw err
1974+
const policy = await minioClient.getBucketPolicy('my-bucketname')
20011975

2002-
console.log(`Bucket policy file: ${policy}`)
2003-
})
1976+
console.log(`Bucket policy file: ${policy}`)
20041977
```
20051978

20061979
<a name="setBucketPolicy"></a>

docs/zh_CN/API.md

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Stream.on('error', function(err) {
337337
## 3. 操作对象
338338

339339
<a name="getObject"></a>
340-
### getObject(bucketName, objectName[, callback])
340+
### async getObject(bucketName, objectName,[ getOpts]): Promise<stream.Readable>
341341

342342
下载对象。
343343

@@ -348,63 +348,54 @@ __参数__
348348
|---|---|---|
349349
|`bucketName` | _string_ | 存储桶名称。 |
350350
|`objectName` | _string_ | 对象名称。 |
351-
|`callback(err, stream)` | _function_ | 回调函数,第一个参数是错误信息。`stream`是对象的内容。如果没有传callback的话,则返回一个`Promise`对象|
351+
|`getOpts` | _string_ | 对象名称|
352352

353353
__示例__
354354

355355

356356
```js
357357
let size = 0
358-
minioClient.getObject('mybucket', 'photo.jpg', function(err, dataStream) {
359-
if (err) {
360-
return console.log(err)
361-
}
362-
dataStream.on('data', function(chunk) {
358+
const dataStream = await minioClient.getObject('mybucket', 'photo.jpg')
359+
dataStream.on('data', function(chunk) {
363360
size += chunk.length
364-
})
365-
dataStream.on('end', function() {
361+
})
362+
dataStream.on('end', function() {
366363
console.log('End. Total size = ' + size)
367-
})
368-
dataStream.on('error', function(err) {
364+
})
365+
dataStream.on('error', function(err) {
369366
console.log(err)
370-
})
371367
})
372368
```
373369
<a name="getPartialObject"></a>
374-
### getPartialObject(bucketName, objectName, offset, length[, callback])
370+
### async getPartialObject(bucketName, objectName, offset,[ length, getOpts]): Promise<stream.Readable>
375371

376372
下载对象中指定区间的字节数组,并返回流。
377373

378374
__参数__
379375

380376

381-
| 参数 | 类型 | 描述 |
382-
|---|---|---|
383-
| `bucketName` | _string_ | 存储桶名称。 |
384-
| `objectName` | _string_ | 对象名称。 |
385-
| `offset` | _number_ | `offset`是从第几个字节始 |
386-
| `length` | _number_ | `length`是要下载的字节数组长度(可选值,如果为空的话则代表从offset一直到文件的末尾)。 |
387-
|`callback(err, stream)` | _function_ | 回调函数,第一个参数是错误信息。`stream`是对象的内容。如果没有传callback的话,则返回一个`Promise`对象。 |
388-
377+
| 参数 | 类型 | 描述 |
378+
|---|---|----------------------------------------------------|
379+
| `bucketName` | _string_ | 存储桶名称。 |
380+
| `objectName` | _string_ | 对象名称。 |
381+
| `offset` | _number_ | `offset`是从第几个字节始 |
382+
| `length` | _number_ | `length`是要下载的字节数组长度(可选值,如果为空的话则代表从offset一直到文件的末尾)。 |
383+
| `getOpts` | object| 获取对象时的额外选项,例如:`{versionId: '...'}` |
389384
__示例__
390385

391386

392387
```js
393388
let size = 0
394389
// reads 30 bytes from the offset 10.
395-
minioClient.getPartialObject('mybucket', 'photo.jpg', 10, 30, function(err, dataStream) {
396-
if (err) {
397-
return console.log(err)
398-
}
399-
dataStream.on('data', function(chunk) {
390+
const dataStream = await minioClient.getPartialObject('mybucket', 'photo.jpg', 10, 30)
391+
dataStream.on('data', function(chunk) {
400392
size += chunk.length
401-
})
402-
dataStream.on('end', function() {
393+
})
394+
dataStream.on('end', function() {
403395
console.log('End. Total size = ' + size)
404-
})
405-
dataStream.on('error', function(err) {
396+
})
397+
dataStream.on('error', function(err) {
406398
console.log(err)
407-
})
408399
})
409400
```
410401

@@ -950,7 +941,7 @@ listener.on('notification', function(record) {
950941
```
951942

952943
<a name="getBucketPolicy"></a>
953-
### getBucketPolicy(bucketName, objectPrefix[, callback])
944+
### async getBucketPolicy(bucketName: string): Promise<string>
954945

955946
获取指定存储桶的访问策略,如果`objectPrefix`不为空,则会取相应对象前缀上的访问策略。
956947

@@ -960,18 +951,13 @@ __参数__
960951
| 参数 | 类型 | 描述 |
961952
|---|---|---|
962953
| `bucketName` | _string_ | 存储桶名称。 |
963-
| `objectPrefix` | _string_ | 用于过滤的对象前缀,`''`代表整个存储桶。 |
964-
| `callback(err, policy)` | _function_ | 如果`err`不是null则代表有错误。`policy`是存储桶策略的字符串表示(`minio.Policy.NONE``minio.Policy.READONLY``minio.Policy.WRITEONLY`,或者`minio.Policy.READWRITE`). 如果没有传callback的话,则返回一个`Promise`对象。 |
965954

966955

967956
```js
968957
// Retrieve bucket policy of 'my-bucketname' that applies to all objects that
969-
// start with 'img-'.
970-
minioClient.getBucketPolicy('my-bucketname', 'img-', function(err, policy) {
971-
if (err) throw err
958+
const policy = await minioClient.getBucketPolicy('my-bucketname')
972959

973-
console.log(`Bucket policy: ${policy}`)
974-
})
960+
console.log(`Bucket policy file: ${policy}`)
975961
```
976962

977963
<a name="setBucketPolicy"></a>
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,11 @@ const s3Client = new Minio.Client({
2626
})
2727

2828
// Get a full object.
29-
s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile', function (e) {
30-
if (e) {
31-
return console.log(e)
32-
}
33-
console.log('done')
34-
})
29+
await s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile')
30+
console.log('done')
3531

3632
//To get a specific version of an object
37-
s3Client.fGetObject(
38-
'my-bucketname',
39-
'my-objectname',
40-
'/tmp/objfile',
41-
{ versionId: '03fd1247-90d9-4b71-a27e-209d484a234b' },
42-
function (e) {
43-
if (e) {
44-
return console.log(e)
45-
}
46-
console.log('success')
47-
},
48-
)
33+
await s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile', {
34+
versionId: '03fd1247-90d9-4b71-a27e-209d484a234b',
35+
})
36+
console.log('success')

0 commit comments

Comments
 (0)