mannprerak2 / cronet.dart

This package binds to Cronet's native API to expose them in Dart.

Home Page:https://pub.dev/packages/cronet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Experimental Cronet Dart bindings

This package binds to Cronet's native API to expose them in Dart.

This is a GSoC 2021 project.

Supported Platforms

Currently, 64 bit Linux and Windows systems are supported.

Requirements

  1. Dart SDK 2.12.0 or above.
  2. CMake 3.15 or above. (If on windows, Visual Studio 2019 with C++ tools)
  3. C++ compiler. (g++/clang/msvc)

Usage

  1. Add package as a dependency in your pubspec.yaml.

  2. Run this from the root of your project.

    Dart CLI

    dart pub get
    dart run cronet:setup # Downloads the cronet binaries.
  3. Import

    import 'package:cronet/cronet.dart';

Note: Internet connection is required to download cronet binaries.

Example

  final client = HttpClient();
  client
      .getUrl(Uri.parse('http://info.cern.ch/'))
      .then((HttpClientRequest request) {
    return request.close();
  }).then((HttpClientResponse response) {
    response.transform(utf8.decoder).listen((contents) {
      print(contents);
    },
      onDone: () => print(
        'Done!'));
  });

See the API comparison with dart:io.

Run Example

cd example_dart
dart run cronet:setup # Downloads the cronet binaries.
dart run

Run Tests

dart pub get
dart run cronet:setup # Downloads the cronet binaries.
dart test --platform vm

You can also verify your cronet binaries using dart run cronet:setup verify. Make sure to have cmake 3.15.

Building Your Own

  1. Make sure you've downloaded your custom version of cronet shared library and filename follows the pattern cronet.86.0.4240.198.<extension> with a prefix lib if on linux. Else, you can build cronet from source using the provided instuctions. Then copy the library to the designated folder. For linux, the files are under .dart_tool/cronet/linux64.

  2. Run dart run cronet:setup build from the root of your project.

Note for Windows: Run step 2 from x64 Native Tools Command Prompt for VS 2019 shell.

About

This package binds to Cronet's native API to expose them in Dart.

https://pub.dev/packages/cronet

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Dart 82.7%Language:C++ 11.1%Language:C 4.7%Language:CMake 1.4%