From 1d1fb0c160286d2c25d50110f833a49ff765de16 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 15 Oct 2015 21:13:37 -0700 Subject: [PATCH] use sync* in _traverse --- tool/grind.dart | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/tool/grind.dart b/tool/grind.dart index d9d37843..17534070 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -60,11 +60,7 @@ test() => new TestRunner().testAsync(files: 'test/validate_templates.dart'); void _concatenateFiles(Directory src, File target) { log('Creating ${target.path}'); - List results = []; - - _traverse(src, '', results); - - String str = results.map((s) => ' ${_toStr(s)}').join(',\n'); + String str = _traverse(src, '').map((s) => ' ${_toStr(s)}').join(',\n'); target.writeAsStringSync(""" // Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details. @@ -85,27 +81,22 @@ String _toStr(String s) { } } -void _traverse(Directory dir, String root, List results) { +Iterable _traverse(Directory dir, String root) sync* { var files = _listSync(dir, recursive: false, followLinks: false); for (FileSystemEntity entity in files) { - String name = path.basename(entity.path); - if (entity is Link) continue; + String name = path.basename(entity.path); if (name == 'pubspec.lock') continue; if (name.startsWith('.') && name != '.gitignore') continue; if (entity is Directory) { - _traverse(entity, '${root}${name}/', results); + yield* _traverse(entity, '${root}${name}/'); } else { - File file = entity; - String fileType = _isBinaryFile(name) ? 'binary' : 'text'; - String data = CryptoUtils.bytesToBase64(file.readAsBytesSync(), + yield '${root}${name}'; + yield _isBinaryFile(name) ? 'binary' : 'text'; + yield BASE64.encode((entity as File).readAsBytesSync(), addLineSeparator: true); - - results.add('${root}${name}'); - results.add(fileType); - results.add(data); } } }