jovial_misc 0.4.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

Miscellaneous small-ish bits of Dart code. It's mostly for my own use, but you're welcome to it. Please attribute it if you do, e.g. with a link to https://bill.jovial.com/. Offered under the MIT license.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

See the individual libraries for usage examples.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.0.1, Jan. 9 2020 #

  • Initial version

0.0.2, 0.0.3, 0.0.4 Jan. 9 2020 #

  • Fix some cosmetic issues

0.1.0 Jan. 9 2020 #

  • All known issues fixed.

0.1.1 #

  • Cosmetic fixes to README and example

0.2.0 #

  • Added the ability to change the endianness of DataInputStream and DataOutputSink.
  • Added float and double to DataInputStream and DataOutputSink.
  • Fixed ByteBufferDataInputStream.readByte() to return a signed byte, as intended.
  • Made the unintentionally public DataInputStream.utf8Decoder into a private value.
  • Documentation improvements.

0.2.1, 0.2.2, 0.2.3 #

  • Documentation improvements

0.3.0 #

  • Improved IsolateStream.fromSink API to make it type-safe.

0.4.0 #

  • Refactored IsolateStream to make the API more pleasing, by making IsolateStreamGenerator

0.4.1 #

  • Added FlushingIOSink

0.4.2 #

  • Tightened up static type checking (implicit-casts: false and implicit-dynamic: false).

0.4.3 #

  • Fixed a bug in DataInputStream, where it was assuming that Uint8List.buffer's first byte was the first byte of the list.

0.4.4 #

  • DataInputStream: Avoid unnecessary copying of underlying byte data.

example/example.dart

import 'dart:async';
import 'dart:io';
import 'package:intl/intl.dart';
import 'package:jovial_misc/io_utils.dart';
import 'package:jovial_misc/isolate_stream.dart';

///
/// Example of using [DataOutputSink] and [DataInputStream] to
/// encode values that are compatible with `java.io.DataInputStream`
/// and `java.io.DataOutputStream`
///
Future<void> data_io_stream_example() async {
  final file = File.fromUri(Directory.systemTemp.uri.resolve('test.dat'));
  final flushable = FlushingIOSink(file.openWrite());
  final out = DataOutputSink(flushable);
  out.writeUTF8('Hello, world.');
  out.close();
  await flushable.done;

  final dis = DataInputStream(file.openRead());
  print(await dis.readUTF8());
  await dis.close();
  await file.delete();
}

///
/// Example of using [IsolateStream] to run a computationally-intensive
/// generator function in an isolate.  We use FizzBuzz as a
/// stand-in for a computationally intensive series of values.
///
Future<void> isolate_stream_example() async {
  const max = 25;
  final fmt = NumberFormat();
  const iterationPause = Duration(milliseconds: 250);
  print('Generating FizzBuzz sequence up to ${fmt.format(max)}');

  final stream = IsolateStream<String>(FizzBuzzGenerator(max));
  // Our stream will be limited to 11 strings in the buffer at a time.
  for (var iter = StreamIterator(stream); await iter.moveNext();) {
    print(iter.current);
    await Future<void>.delayed(iterationPause);
  }
  // Note that the producer doesn't run too far ahead of the consumer,
  // because the buffer is limited to 30 strings.
}

/// The generator that runs in a separate isolate.
class FizzBuzzGenerator extends IsolateStreamGenerator<String> {
  final int _max;

  FizzBuzzGenerator(this._max) {
    print('FizzBuzzGenerator constructor.  Note that this only runs once.');
    // This demonstrats that when FizzBuzzGenerator is sent to the other
    // isolate, the receiving isolate does not run the constructor.
  }

  @override
  Future<void> generate() async {
    for (var i = 1; i <= _max; i++) {
      var result = '';
      if (i % 3 == 0) {
        result = 'Fizz';
      }
      if (i % 5 == 0) {
        result += 'Buzz';
      }
      print('        Generator sending $i $result');
      if (result == '') {
        await sendValue(i.toString());
      } else {
        await sendValue(result);
      }
    }
  }

  @override
  int sizeOf(String value) => 1; // 1 entry

  @override
  int get bufferSize => 7; // Buffer up to 7 entries
}

///
/// Run the examples
///
void main() async {
  await data_io_stream_example();
  print('');
  await isolate_stream_example();
}

Use this package as a library

1. Depend on it

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


dependencies:
  jovial_misc: ^0.4.4

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:jovial_misc/io_utils.dart';
import 'package:jovial_misc/isolate_stream.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
40
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:jovial_misc/io_utils.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:jovial_misc/io_utils.dartdart:io

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
async ^2.4.0 2.4.1
collection ^1.14.11 1.14.13
convert ^2.1.1 2.1.1
intl ^0.16.0 0.16.1
pointycastle ^1.0.2 1.0.2
Transitive dependencies
charcode 1.1.3
path 1.7.0
typed_data 1.2.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0