1 // import 'dart:convert'; 2 import 'dart:io'; 3 4 main() async { 5 var src = File('./lib/convert/source.txt'); 6 var output = File('./lib/convert/output.txt'); 7 8 var ins = src.openRead(); 9 var encoded = convert(ins, 128); 10 var outs = output.openWrite(); 11 await encoded.pipe(outs); 12 outs.close(); 13 14 // the second transform. 15 var output2 = File('./lib/convert/output2.txt'); 16 var outs2 = output2.openWrite(); 17 await convert(output.openRead(), -128).pipe(outs2); 18 outs2.close(); 19 } 20 21 Stream<List<int>> convert(Stream<List<int>> source, 22 [int key = 128, int base = 256]) async* { 23 await for (var chunk in source) { 24 yield encode(chunk, key, base); 25 } 26 } 27 28 List<int> encode(List<int> original, [int key = 128, int base = 256]) { 29 var encoded = List<int>(original.length); 30 for (var i = 0; i < original.length; i++) { 31 encoded[i] = (original[i] + key) % base; 32 } 33 return encoded; 34 }