我正在尝试访问一个Web服务,该服务使用angular5的httpclient返回无休止的(文本)数据流。到目前为止,我可以做到这一点,直到res.partialText
超出javascript的处理能力,然后崩溃:
var req = new HttpRequest('GET', 'http://localhost:5001/data',
{ reportProgress: true, responseType: 'text', observe: 'response' });
http.request(req).subscribe((res: any) => {
if (3 === res.type) {
var buff: string = leftovers + res.partialText.substring(read, res.partialText.length);
var lastBar: number = buff.lastIndexOf('|');
leftovers = buff.substring(lastBar + 1);
var values: DsMessage[] = my.parse(buff.substring(0, lastBar));
read = res.loaded;
my._data.next(values);
}
else if (HttpEventType.Response === res.type) {
my._data.complete();
}
});
在我处理数据流时,是否可以访问该数据流并丢弃数据?