dospace 0.12.12

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

DOSpace #

Client library to interact with the DigitalOcean Spaces API.

Usage #

A simple usage example:

import 'dart:async';
import 'package:dospace/dospace.dart' as dospace;

main() async {
  dospace.Spaces spaces = new dospace.Spaces(
    region: "nyc3",
    accessKey: "7Q7GAFJ4IXHQVLBRXSRX",
    secretKey: "2JLXa9RqPwpavBkC7dt1MHWUDfd6onaXTXTfSYc5eQ0",
  );
  for (String name in await spaces.listAllBuckets()) {
    print('bucket: ${name}');
    dospace.Bucket bucket = spaces.bucket(name);
    await for (dospace.BucketContent content in bucket.listContents(maxKeys: 3)) {
       print('key: ${content.key}');
    }
  }
  String etag = await spaces.bucket('example').uploadFile(
    'README.md', 'README.md', 'text/plain', dospace.Permissions.public);
  print('upload: $etag');
  await spaces.close();
}

References #

0.12.11 #

  • Switch from http_client package to http package
  • Web compatibility

0.11.9 #

  • Require passing an HTTP Client in the constructor

0.10.7 #

  • Add support for pre-signed uploads

0.10.6 #

  • Fixed enum case

0.9.5 #

  • Adjust version dependency

0.9.4 #

  • Implement file upload

0.9.3 #

  • Simplify library usage

0.9.2 #

  • Initial version

example/dospace_example.dart

import 'dart:convert';
import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:dospace/dospace.dart' as dospace;
import 'package:http/http.dart' as http;

const String region = "nyc3";
const String accessKey = "";
const String secretKey = "";
const String bucketName = "";

main() async {
  dospace.Spaces spaces = new dospace.Spaces(
    region: region,
    accessKey: accessKey,
    secretKey: secretKey,
  );
  for (String name in await spaces.listAllBuckets()) {
    print('bucket: ${name}');
    dospace.Bucket bucket = spaces.bucket(name);
    await for (dospace.BucketContent content
        in bucket.listContents(maxKeys: 3)) {
      print('key: ${content.key}');
    }
  }
  dospace.Bucket bucket = spaces.bucket(bucketName);
  String etag = await bucket.uploadFile(
      'README.md', 'README.md', 'text/plain', dospace.Permissions.public);
  print('upload: $etag');

  // Basic pre-signed URL
  print('list buckets: ${spaces.preSignListAllBuckets()}');

  // Basic pre-signed upload
  {
    String preSignUrl = bucket.preSignUpload('README.md');
    print('upload url: ${preSignUrl}');
    var httpClient = new http.Client();
    var httpRequest = new http.Request('PUT', Uri.parse(preSignUrl));
    http.StreamedResponse httpResponse = await httpClient.send(httpRequest);
    String body = await utf8.decodeStream(httpResponse.stream);
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
    await httpClient.close();
  }

  // Pre-signed upload with specific payload
  {
    var input = new File('README.md');
    int contentLength = await input.length();
    Digest contentSha256 = await sha256.bind(input.openRead()).first;
    String preSignUrl = bucket.preSignUpload('README.md',
        contentLength: contentLength, contentSha256: contentSha256);
    print('strict upload url: ${preSignUrl}');
    var httpClient = new http.Client();
    var httpRequest = new http.Request('PUT', Uri.parse(preSignUrl));
    http.StreamedResponse httpResponse = await httpClient.send(httpRequest);
    String body = await utf8.decodeStream(httpResponse.stream);
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
    await httpClient.close();
  }

  print('done');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dospace: ^0.12.12

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dospace/dospace.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
89
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/dospace_client.dart. (-5.36 points)

Analysis of lib/src/dospace_client.dart reported 11 hints, including:

line 39 col 41: Unnecessary new keyword.

line 51 col 28: Unnecessary new keyword.

line 56 col 13: Unnecessary new keyword.

line 86 col 21: Unnecessary new keyword.

line 107 col 35: Unnecessary new keyword.

Fix lib/src/dospace_bucket.dart. (-4.41 points)

Analysis of lib/src/dospace_bucket.dart reported 9 hints, including:

line 50 col 37: Unnecessary new keyword.

line 96 col 23: Unnecessary new keyword.

line 118 col 9: Unnecessary new keyword.

line 136 col 13: Unnecessary new keyword.

line 151 col 28: Unnecessary new keyword.

Fix lib/src/dospace_spaces.dart. (-1.49 points)

Analysis of lib/src/dospace_spaces.dart reported 3 hints:

line 28 col 14: Unnecessary new keyword.

line 42 col 24: Unnecessary new keyword.

line 57 col 9: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Package is getting outdated. (-60 points)

The package was last published 83 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
crypto ^2.0.6 2.1.5
http ^0.12.0 0.12.1
meta ^1.1.5 1.2.1
xml ^3.0.1 3.7.0 4.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.13
convert 2.1.1
http_parser 3.1.4
path 1.7.0
pedantic 1.9.1
petitparser 3.0.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
Dev dependencies
ini ^2.0.1
test ^1.0.0