Skip to content

Commit

Permalink
Merge branch 'master' into patch-6
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 authored Sep 13, 2024
2 parents 17f8f0a + 38913da commit 0260a58
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 190 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/dart.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: lint

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1

- run: dart pub get
- run: dart analyze

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1

- run: dart pub get
- run: dart format --output=none --set-exit-if-changed .
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: test

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1

- run: dart pub get
- run: dart test
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
This is the _unofficial_ MinIO Dart Client SDK that provides simple APIs to access any Amazon S3 compatible object storage server.

<p align="center">
<a href="https://github.com/xtyxtyx/minio-dart/actions/workflows/dart.yml">
<img src="https://github.com/xtyxtyx/minio-dart/workflows/Dart/badge.svg">
<a href="https://github.com/xtyxtyx/minio-dart/actions/workflows/test.yml">
<img src="https://github.com/xtyxtyx/minio-dart/workflows/test/badge.svg">
</a>
<a href="https://pub.dev/packages/minio">
<img src="https://img.shields.io/pub/v/minio">
Expand All @@ -16,7 +16,6 @@ This is the _unofficial_ MinIO Dart Client SDK that provides simple APIs to acce
</a>
</p>


## API

| Bucket operations | Object operations | Presigned operations | Bucket Policy & Notification operations |
Expand All @@ -32,7 +31,6 @@ This is the _unofficial_ MinIO Dart Client SDK that provides simple APIs to acce
| [listAllObjectsV2] | [removeObjects] | | |
| | [removeIncompleteUpload] | | |


## Usage

### Initialize MinIO Client
Expand Down Expand Up @@ -69,6 +67,7 @@ final minio = Minio(
```

**File upload**

```dart
import 'package:minio/io.dart';
import 'package:minio/minio.dart';
Expand All @@ -89,6 +88,7 @@ For complete example, see: [example]
> To use `fPutObject()` and `fGetObject`, you have to `import 'package:minio/io.dart';`
**Upload with progress**

```dart
import 'package:minio/minio.dart';
Expand All @@ -100,8 +100,8 @@ void main() async {
);
await minio.putObject(
'mybucket',
'myobject',
'mybucket',
'myobject',
Stream<Uint8List>.value(Uint8List(1024)),
onProgress: (bytes) => print('$bytes uploaded'),
);
Expand Down Expand Up @@ -139,11 +139,10 @@ Contributions to this repository are welcome.

## License

MIT
[MIT](./LICENSE)

[tracker]: https://github.com/xtyxtyx/minio-dart/issues
[example]: https://pub.dev/packages/minio#-example-tab-
[link text itself]: http://www.reddit.com
[example]: https://pub.dev/packages/minio/example

[makeBucket]: https://pub.dev/documentation/minio/latest/minio/Minio/makeBucket.html
[listBuckets]: https://pub.dev/documentation/minio/latest/minio/Minio/listBuckets.html
Expand Down
17 changes: 4 additions & 13 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

include: package:mostly_reasonable_lints/analysis_options.yaml
analyzer:
# exclude:
# - path/to/excluded/files/**
errors:
avoid_print: ignore
prefer_const_declarations: ignore
17 changes: 12 additions & 5 deletions example/minio_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ void main() async {
print('bucket $bucket already exists');
}

final poller = minio.listenBucketNotification(bucket, events: [
's3:ObjectCreated:*',
]);
final poller = minio.listenBucketNotification(
bucket,
events: [
's3:ObjectCreated:*',
],
);
poller.stream.listen((event) {
print('--- event: ${event['eventName']}');
});
Expand Down Expand Up @@ -53,12 +56,16 @@ void main() async {

await minio.listObjects(bucket).forEach((chunk) {
print('--- objects:');
chunk.objects.forEach((o) => print(o.key));
for (var o in chunk.objects) {
print(o.key);
}
});

await minio.listObjectsV2(bucket).forEach((chunk) {
print('--- objects(v2):');
chunk.objects.forEach((o) => print(o.key));
for (var o in chunk.objects) {
print(o.key);
}
});

final stat = await minio.statObject(bucket, object);
Expand Down
8 changes: 4 additions & 4 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ extension MinioX on Minio {
IOSink partFileStream;
var offset = 0;

final rename = () {
partFile.rename(filePath);
};
Future<void> rename() async {
await partFile.rename(filePath);
}

if (await partFile.exists()) {
final localStat = await partFile.stat();
if (stat.size == localStat.size) return rename();
if (stat.size == localStat.size) return await rename();
offset = localStat.size;
partFileStream = partFile.openWrite(mode: FileMode.append);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/models.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'src/minio_models_generated.dart';
export 'src/minio_models.dart';
export 'src/minio_models_generated.dart';
28 changes: 19 additions & 9 deletions lib/src/minio.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// ignore_for_file: deprecated_member_use

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:minio/models.dart';
import 'package:minio/src/minio_client.dart';
import 'package:minio/src/minio_errors.dart';
import 'package:minio/src/minio_helpers.dart';
import 'package:minio/src/minio_models.dart';
import 'package:minio/src/minio_models_generated.dart';
import 'package:minio/src/minio_poller.dart';
import 'package:minio/src/minio_sign.dart';
import 'package:minio/src/minio_stream.dart';
Expand All @@ -14,9 +17,6 @@ import 'package:minio/src/utils.dart';
import 'package:xml/xml.dart' as xml;
import 'package:xml/xml.dart' show XmlElement;

import '../models.dart';
import 'minio_helpers.dart';

class Minio {
/// Initializes a new client object.
Minio({
Expand Down Expand Up @@ -812,7 +812,7 @@ class Minio {
// 'expiration' is mandatory field for S3.
// Set default expiration date of 7 days.
var expires = DateTime.now().toUtc();
expires.add(Duration(days: 7));
expires.add(const Duration(days: 7));
postPolicy.setExpires(expires);
}

Expand All @@ -824,9 +824,11 @@ class Minio {
postPolicy.formData['x-amz-algorithm'] = 'AWS4-HMAC-SHA256';

postPolicy.policy['conditions'].add(
['eq', r'$x-amz-credential', accessKey + '/' + getScope(region, date)]);
['eq', r'$x-amz-credential', '$accessKey/${getScope(region, date)}'],
);

postPolicy.formData['x-amz-credential'] =
accessKey + '/' + getScope(region, date);
'$accessKey/${getScope(region, date)}';

if (sessionToken != null) {
postPolicy.policy['conditions']
Expand All @@ -841,8 +843,16 @@ class Minio {

postPolicy.formData['x-amz-signature'] = signature;
final url = _client
.getBaseRequest('POST', postPolicy.formData['bucket'], null, region,
null, null, null, null)
.getBaseRequest(
'POST',
postPolicy.formData['bucket'],
null,
region,
null,
null,
null,
null,
)
.url;
var portStr = (port == 80 || port == 443) ? '' : ':$port';
var urlStr = '${url.scheme}://${url.host}$portStr${url.path}';
Expand Down
Loading

0 comments on commit 0260a58

Please sign in to comment.