Skip to content

Commit

Permalink
remove dart:io from package
Browse files Browse the repository at this point in the history
  • Loading branch information
mars3142 committed Jun 25, 2020
1 parent 98ab868 commit 5ce57c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
10 changes: 10 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import 'dart:async';
import 'dart:io';

import 'package:freewig/freewig.dart';

Future<Cartridge> parseFile(File file) async {
final bytes = await file.readAsBytes();
final completer = Completer<Cartridge>();
await Future<Cartridge>(() => parseData(bytes))
.then(completer.complete)
.catchError(completer.completeError);
return completer.future;
}

void main(List<String> arguments) async {
var file = File(arguments[0]); // path/incl/cartridge.gwc
var cartridge = await parseFile(file);
Expand Down
14 changes: 0 additions & 14 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,11 @@
* all copies or substantial portions of the Software.
*/

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'binary_reader.dart';
import 'models/cartridge.dart';

/// Try to parse a file and create a [Cartridge]
///
/// If the file is a valid GWC file, the result will be [Cartridge] or null, if the parser failed.
Future<Cartridge> parseFile(File file) async {
final bytes = await file.readAsBytes();
final completer = Completer<Cartridge>();
await Future<Cartridge>(() => parseData(bytes))
.then(completer.complete)
.catchError(completer.completeError);
return completer.future;
}

/// Parses a byte list and create a [Cartridge]
///
/// If the byte list is a valid GWC file, the result will be [Cartridge] or null, if the parser failed.
Expand Down
12 changes: 11 additions & 1 deletion test/gwc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@
* all copies or substantial portions of the Software.
*/

import 'dart:async';
import 'dart:io';

import 'package:test/test.dart';
import 'package:freewig/freewig.dart';

Future<Cartridge> parseFile(File file) async {
final bytes = await file.readAsBytes();
final completer = Completer<Cartridge>();
await Future<Cartridge>(() => parseData(bytes))
.then(completer.complete)
.catchError(completer.completeError);
return completer.future;
}

void main() {
group('Cartridge TESTING.GWC', () {
Cartridge cartridgeData;
Expand All @@ -38,7 +48,7 @@ void main() {
expect(cartridgeData.completionCode, "ABCDEFGHIJKLMNOP");
});

test('Gartridge has 2 objects', () {
test('Cartridge has 2 objects', () {
expect(cartridgeData.mediaObjects.length, 2);
});
});
Expand Down

0 comments on commit 5ce57c2

Please sign in to comment.