Viewing version 0.1.1. Open the latest package page.
universal_io
0.1.1Supports a subset of 'dart:io' in all platforms, including the browser.
Readme
Introduction
A Dart package that supports a subset of dart:io in all platforms, including the browser (where it normally doesn't work).
Typically you just import "package:universal_io/io.dart" (instead of "dart:io"):
- In the Dart VM and Flutter, the library exports dart:io.
- In browser: the library exports its own, compatible classes.
Licensed under the MIT License. Much of the source code was adopted from the original 'dart:io' in Dart SDK, which was licensed under a BSD-style license. See LICENSE for all licenses.
Development
- Star the project at: github.com/terrier989/dart-universal_io
- Report issues at the Github issue tracker.
- Create pull requests if you contribute source code.
Features
- Platform information
- Information such as operating system, locale, and stdin/stdout. You can override the behavior.
- HTTP client
- In browser, the connection to the server is established only after you have committed request
body by calling
HttpClientRequestmethodclose().
- In browser, the connection to the server is established only after you have committed request
body by calling
- File access
- In browsers, access to all directories and files is denied. You can override the behavior.
- Sockets
- In most browsers, an attempt to create sockets throws UnsupportedError. You can override the behavior.
- In Chrome OS apps, we use chrome.sockets.tcp and chrome.sockets.udp APIs.
Getting started
Add dependency
In pubspec.yaml:
dependencies:
universal_io: ^0.1.0
Override behavior
import 'dart:async';
import 'package:universal_io/io.dart';
import 'package:universal_io/io_driver.dart';
void main() async {
// Set IO driver
IODriver.zoneLocal.defaultValue = new MyDriver();
// Do something
final socket = await Socket.connect("google.com", 80);
socket.close();
}
class MyDriver extends IODriver {
@override
Future<Socket> connectSocket(host, int port,
{sourceAddress, Duration timeout}) {
print("Attempting to connect to '$host:$port'");
return super.connectSocket(host, port);
}
}
Use Chrome OS driver
import 'package:universal_io/io.dart';
import 'package:universal_io/io_driver.dart';
import 'package:universal_io_for_chrome_os/io_driver_chrome_os.dart';
void main() async {
// Use Chrome OS driver for IO
IODriver.zoneLocal.defaultValue = new ChromeIODriver();
// ...
}
Changelog
0.1.0
- Added sockets, overrides, and other features.
0.0.1
- Initial release.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'universal_io:0.1.1'pubspec.yaml
name: universal_io
version: 0.1.1
description: Supports a subset of 'dart:io' in all platforms, including the browser.
homepage: https://github.com/terrier989/dart-universal_io
author: terrier989 <terrier989@gmail.com>
environment:
sdk: '>=2.0.0 <3.0.0'
dependencies:
http: '^0.12.0'
raw: '^0.2.0'
typed_data: '^1.1.6'
stream_channel: '^1.6.8'
dev_dependencies:
async: '^2.0.8'
pedantic: '^1.0.0'
test: '^1.4.0'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | Cached · Upstream SHA-256 matched | Download | a8aa4b4f…6f259b |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | adeca974…128b76 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | b4d0cce4…efe2b0 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | debb79ed…36d4ee |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | 0b8f764b…a054e5 |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 7f879f79…0ee63f |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | a185c8ca…f5f7c2 |
| 0.5.1 | Cached · Upstream SHA-256 matched | Download | 47881238…a13ab3 |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | 0465c285…30fb21 |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | 0b6ff36a…c988ef |
| 0.7.1 | Cached · Upstream SHA-256 matched | Download | 3fd33123…e947d1 |
| 0.7.2 | Cached · Upstream SHA-256 matched | Download | ab916807…e30f36 |
| 0.7.3 | Cached · Upstream SHA-256 matched | Download | 9918c2ae…d6e492 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | 9e971384…0ffa98 |
| 0.8.1 | Cached · Upstream SHA-256 matched | Download | 39dd369c…e29abc |
| 0.8.2 | Cached · Upstream SHA-256 matched | Download | 873f9c3e…b5629f |
| 0.8.3 | Cached · Upstream SHA-256 matched | Download | 0da20598…979fb2 |
| 0.8.4 | Cached · Upstream SHA-256 matched | Download | b1c84301…3b7ec0 |
| 0.8.5 | Cached · Upstream SHA-256 matched | Download | 50a660f9…874883 |
| 0.8.6 | Cached · Upstream SHA-256 matched | Download | e700bb7c…986502 |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 5da439c3…bddf21 |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | 2c0fa418…f6cb08 |
| 1.0.2 | Cached · Upstream SHA-256 matched | Download | 22c5875f…f9e8db |
| 2.0.0-nullsafety.0 | Cached · Upstream SHA-256 matched | Download | 2fe15fca…c8acd3 |
| 2.0.0-nullsafety.1 | Cached · Upstream SHA-256 matched | Download | 2c94fd97…a42cfa |
| 2.0.0-nullsafety.2 | Cached · Upstream SHA-256 matched | Download | ad7e7015…8099d1 |
| 2.0.0 | Cached · Upstream SHA-256 matched | Download | 6ba43dc8…75397e |
| 2.0.1 | Cached · Upstream SHA-256 matched | Download | ffb7b33e…21e456 |
| 2.0.2 | Cached · Upstream SHA-256 matched | Download | 02437682…2d832b |
| 2.0.3 | Cached · Upstream SHA-256 matched | Download | ee2ecc7c…bc6f23 |
| 2.0.4 | Cached · Upstream SHA-256 matched | Download | 79f78dda…f03cef |
| 2.0.5 | Cached · Upstream SHA-256 matched | Download | 2730b3fc…680b85 |
| 2.1.0 | Cached · Upstream SHA-256 matched | Download | 070d8fcc…745007 |
| 2.2.0 | Cached · Upstream SHA-256 matched | Download | 06866290…48005d |
| 2.2.1 | Cached · Upstream SHA-256 matched | Download | 302df7ff…d51401 |
| 2.2.2 | Cached · Upstream SHA-256 matched | Download | 1722b2dc…ba9aad |
| 2.2.3 | Cached · Upstream SHA-256 matched | Download | ba9dde5f…2edf04 |
| 2.3.0 | Cached · Upstream SHA-256 matched | Download | 6780711d…79530a |
| 2.3.1 | Cached · Upstream SHA-256 matched | Download | f63cbc48…9301e2 |
Dependencies
http "^0.12.0"
raw "^0.2.0"
stream_channel "^1.6.8"
typed_data "^1.1.6"