jsonstreamreader 1.1.9 jsonstreamreader: ^1.1.9 copied to clipboard
This project processes local and remote json files/sources by splitting it into smaller chunks, with automatic garbage collecting.
import 'package:jsonstreamreader/jsonstreamreader.dart';
import 'dart:async';
void main() {
RemoteSource f =
new RemoteSource('https://jsonplaceholder.typicode.com/posts');
f.setBody({'userId': '1'});
Streamer s = new Streamer(f, chunksize: 100);
//Not Ready to start reading so I use hault
Reader r = new Reader(s, combine: 1)..hault();
//StreamReader r = new StreamReader(s, combine: 1)..hault();
r.trailing((dynamic value, String key) {
print("key is ${key} and value is ${value}");
});
///r.trailing.listen((StreamItem item) {
/// print("key is ${item.key} and value is ${item.value}");
///});
r.progress((p) {
print(p);
}).done(() {
print('Completed');
}).fail((error) {
print(error);
});
///r.progress.listen((double p) {
/// print("completed ${p}%");
///});
///r.done.listen((_) {
/// print("completed");
///});
///r.error.listen((error) {
/// print(error);
///});
new Timer(new Duration(seconds: 1), () {
//start reading
r.begin();
});
FileState.notinuse.listen((d) {
print('this file is free to delete');
print(d);
});
r.onpause((ReaderState state) {
print(state.toString());
});
///Pause the reader
new Timer(new Duration(seconds: 3), () {
r.pause().then((ReaderState state) {
//here you code store state.toString() in a file or just resume
new Timer(new Duration(seconds: 3), () {
r.resume();
});
});
});
f.downloaded.listen((onData) {
//File will always be download before parsing is done
//but parsing is started as soon as data is available,i.e while the file is downloading
print('File has been downloaded');
});
f.download();
}