I have a Dart/Flutter mobile app that configures itself by downloading files from a server. The files are ZLib compressed, headlessly, and this process has always worked very well - up until now. Here is the relevant code
static Future<String> fileFetch(String url) async
{
final HttpClientRequest request = await HttpClient().getUrl(Uri.parse(url));
final HttpClientResponse response = await request.close();
return await response.pipe(Accumulator());
}
where the Acccumulator class handles the actual file download + ZLib decoding
import 'dart:io';
import 'dart:async';
class Accumulator extends StreamConsumer<List<int>>
{
List<int> accu = List.empty(growable:true);
String originalText()
{
ZLibCodec zlc = ZLibCodec(raw:true);
print('Accu ${accu.length}');
List<int> uncompd = zlc.decode(accu);
String text = String.fromCharCodes(uncompd);
return text;
}
void whenData(List<int> data){accu.addAll(data);}
void whenErr(e){XLog.e('Accu',e.toString());}
@override
Future<void> addStream(Stream<List<int>> s) async
{
s.listen(whenData);
return;
}
@override
Future<dynamic> close() async
{
return Future.value(originalText());
}
}
For the most part the orignalText being returned is JSON. The offending file that has now started causing an incomplete file download is 132Kb in length and I find that only 42894 bytes of the original (compressed) file are being downloaded.
Why is this happening - intrinsic limits on how much can be handled by the Accumulator?
from Dart/Flutter HTTP response is incomplete when downloading large files
No comments:
Post a Comment