Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
name: Dart CI

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
format:
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Print version
run: dart --version
- name: Verify formatting
run: dart format --set-exit-if-changed .
analyze:
needs: format
runs-on: ubuntu-slim
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [stable, beta, dev]
sdk: [3.6, stable, dev]
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Print version
run: dart --version
- name: Install dependencies
run: dart pub get
- name: Run tests
run: dart test --platform vm
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .
- name: Analyze project source
run: dart analyze
run: dart analyze
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- uses: browser-actions/setup-chrome@v2
- name: Print version
run: dart --version
- name: Install dependencies
run: dart pub get
- name: Run tests (VM)
run: dart test --platform vm
- name: Run tests (Chrome)
run: dart test --platform chrome
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.3.0
* Adds `Platform.lineTerminator`.
* Lowers minimum SDK constraint for developers who haven't migrated to the latest SDK.

# 2.2.3
* Fixes a bug in new Dart SDK versions.

Expand Down
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@
[![Github Actions CI](https://github.com/dint-dev/universal_io/workflows/Dart%20CI/badge.svg)](https://github.com/dint-dev/universal_io/actions)

# Overview
A cross-platform [dart:io](https://api.dart.dev/stable/2.19.2/dart-io/dart-io-library.html) that
works on all platforms, including browsers.
A cross-platform [dart:io](https://api.dart.dev/stable/2.19.2/dart-io/dart-io-library.html) that works on all platforms, including browsers.

You can simply replace _dart:io_ imports with _package:universal_io/io.dart_.
You can simply replace _dart:io_ imports with _package:universal_io/universal_io.dart_.

Licensed under the [Apache License 2.0](LICENSE).
Some of the source code was derived [from Dart SDK](https://github.com/dart-lang/sdk/tree/master/sdk/lib/io),
which was obtained under the BSD-style license of Dart SDK. See LICENSE file for details.

## APIs added on top of "dart:io"
* [newUniversalHttpClient](https://pub.dev/documentation/universal_io/latest/universal_io/newUniversalHttpClient.html)
* Returns BrowserHttpClient on browsers and the normal "dart:io" HttpClient on other platforms.
* [BrowserHttpClient](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClient-class.html)
* A subclass of "dart:io" [HttpClient](https://api.dart.dev/stable/2.19.2/dart-io/HttpClient-class.html)
that works on browsers.
* [BrowserHttpClientRequest](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientRequest-class.html)
* A subclass of "dart:io" [HttpClientRequest](https://api.dart.dev/stable/2.19.2/dart-io/HttpClientRequest-class.html)
that works on browsers.
* [BrowserHttpClientResponse](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientResponse-class.html)
* A subclass of "dart:io" [HttpClientResponse](https://api.dart.dev/stable/2.19.2/dart-io/HttpClientResponse-class.html)
that works on browsers.
* [BrowserHttpClientException](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientException-class.html)
* An exception that helps you understand why a HTTP request on a browser may have failed
(see explanation below).
that works in browsers.
* See also
[BrowserHttpClientRequest](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientRequest-class.html),
[BrowserHttpClientResponse](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientResponse-class.html),
and [BrowserHttpClientException](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientException-class.html).
* Uses XMLHttpRequest in browsers. WASM-compatible.

## Other features
The following features may be deprecated in the future versions (3.x) of the package:
Expand All @@ -46,24 +39,25 @@ The following features may be deprecated in the future versions (3.x) of the pac
* We appreciate feedback, issue reports, and pull requests.

## Similar packages
* [universal_html](https://pub.dev/packages/universal_html) (cross-platform _dart:html_)
* [universal_html](https://pub.dev/packages/universal_html) (cross-platform DOM, CSS, etc.)


# Getting started
## 1.Add dependency
In pubspec.yaml:
```yaml
dependencies:
universal_io: ^2.2.3
universal_io: ^2.3.0
```

## 2.Use HTTP client
```dart
import 'package:universal_io/io.dart';
// Replace 'dart:io' imports with the following:
import 'package:universal_io/universal_io.dart';

Future<void> main() async {
// HttpClient can be used in browser too!
HttpClient httpClient = newUniversalHttpClient(); // Recommended way of creating HttpClient.
final httpClient = HttpClient(); // Recommended way of creating HttpClient.
final request = await httpClient.getUrl(Uri.parse("https://dart.dev/"));
final response = await request.close();
}
Expand Down
13 changes: 1 addition & 12 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/// Cross-platform implementation of "dart:io" that works on browsers too.
///
/// # Usage
/// Replace imports of "dart:io" with:
/// ```
/// import 'package:universal_io/io.dart';
/// ```
library universal_io;

export 'src/_exports_in_vm.dart'
if (dart.library.html) 'src/_exports_in_browser.dart'
if (dart.library.js) 'src/_exports_in_nodejs.dart';
export 'universal_io.dart';
Loading