Update README with example
This commit is contained in:
parent
d63c673f1c
commit
f56230347e
55
README.md
55
README.md
|
@ -7,3 +7,58 @@ INI parser for HyperTuner written in Dart.
|
|||
## Roadmap
|
||||
|
||||
Checkout Roadmap issue: <https://github.com/hyper-tuner/ini_parser/issues/2>
|
||||
|
||||
## Example usage
|
||||
|
||||
from `example/save_as_json.dart`:
|
||||
|
||||
```dart
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ini_parser/ini_parser.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
void main() async {
|
||||
final timer = Stopwatch()..start();
|
||||
const fileNames = [
|
||||
{
|
||||
'ecosystem': 'speeduino',
|
||||
'name': '202207',
|
||||
},
|
||||
{
|
||||
'ecosystem': 'fome',
|
||||
'name': 'fome_proteus_f4',
|
||||
},
|
||||
];
|
||||
|
||||
for (final fileName in fileNames) {
|
||||
final raw = File(
|
||||
p.join(
|
||||
Directory.current.path,
|
||||
'test/data/${fileName['ecosystem']}/ini/${fileName['name']}.ini',
|
||||
),
|
||||
).readAsStringSync();
|
||||
final config = await INIParser(raw).parse();
|
||||
final json = const JsonEncoder.withIndent(' ').convert(config);
|
||||
|
||||
File(
|
||||
p.join(
|
||||
Directory.current.path,
|
||||
'test/data/${fileName['ecosystem']}/json/${fileName['name']}.json',
|
||||
),
|
||||
).writeAsStringSync(json);
|
||||
}
|
||||
|
||||
// ignore: avoid_print
|
||||
print('Done in ${timer.elapsedMilliseconds}ms');
|
||||
}
|
||||
```
|
||||
|
||||
Compile and run:
|
||||
|
||||
```bash
|
||||
dart compile exe example/save_as_json.dart
|
||||
|
||||
./example/save_as_json
|
||||
```
|
||||
|
|
|
@ -24,12 +24,8 @@ void main() async {
|
|||
'test/data/${fileName['ecosystem']}/ini/${fileName['name']}.ini',
|
||||
),
|
||||
).readAsStringSync();
|
||||
final parser = INIParser(raw);
|
||||
|
||||
final config = await parser.parse();
|
||||
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
final json = encoder.convert(config);
|
||||
final config = await INIParser(raw).parse();
|
||||
final json = const JsonEncoder.withIndent(' ').convert(config);
|
||||
|
||||
File(
|
||||
p.join(
|
||||
|
|
Loading…
Reference in New Issue