export default (url, callback) => {
  const xhr = new XMLHttpRequest();
  let pos = 0;

  const processChunk = (chunk) => {
    callback(null, chunk);
  };

  xhr.onprogress = () => {
    xhr
      .response
      .slice(pos)
      .split('\n')
      .slice(0, -1)
      .forEach((part) => {
        processChunk(part);
        pos += part.length + 1;
      });
  };

  xhr.onload = () => {
    const chunk = xhr.response.slice(pos);
    if (chunk) processChunk(chunk);
    callback();
  };

  xhr.onerror = () => {
    callback(Error('Connection failed'));
  };

  xhr.responseType = 'text';
  xhr.open('GET', url);
  xhr.send();
};


@@ -1,18 +1,914 @@
-export default
+const fetchSupported = window.fetch !== undefined;%0A%0Aconst streamJsonFetch = (url, callback) =%3E %7B%0A  fetch(url).then((response) =%3E %7B%0A    const reader = response.body.getReader();%0A    let partial = '';%0A    const decoder = new TextDecoder();%0A    const parseResult = (result) =%3E %7B%0A      partial += decoder.decode(result.value %7C%7C new Uint8Array(), %7B%0A        stream: !result.done,%0A      %7D);%0A      const pieces = partial.split('%5Cn');%0A      const count = pieces.length;%0A      if (!result.done) %7B%0A        partial = pieces%5Bcount - 1%5D;%0A      %7D else %7B%0A        callback();%0A      %7D%0A      for (let i = 0; i %3C count - 1; i++) %7B%0A        callback(null, pieces%5Bi%5D);%0A      %7D%0A      if (!result.done) %7B%0A        return readFromResponse();%0A      %7D%0A    %7D;%0A    const readFromResponse = () =%3E (%0A      reader%0A        .read()%0A        .then(parseResult)%0A        .catch(callback)%0A    );%0A    readFromResponse();%0A  %7D);%0A%7D;%0A%0Aconst streamJsonXHR =
  (ur
@@ -992,21 +992,21 @@
  process
-Chunk
+Piece
  = (chun
@@ -1076,16 +1076,31 @@
 =%3E %7B%0A   
+ const pieces =
  xhr%0A   
@@ -1152,58 +1152,91 @@
 %5Cn')
+;
 %0A    
-  .slice(0, -1)%0A      .forEach((part) =%3E %7B%0A  
+for (let i = 0; i %3C pieces.length - 1; i++) %7B%0A      const piece = pieces%5Bi%5D;%0A
     
@@ -1248,23 +1248,22 @@
 cess
-Chunk(part
+Piece(piece
 );%0A
-  
     
@@ -1272,19 +1272,20 @@
 pos += p
-art
+iece
 .length 
@@ -1293,21 +1293,17 @@
  1;%0A    
-  %7D);
+%7D
 %0A  %7D;%0A%0A 
@@ -1334,21 +1334,21 @@
   const 
-chunk
+piece
  = xhr.r
@@ -1375,21 +1375,21 @@
     if (
-chunk
+piece
 ) proces
@@ -1393,19 +1393,19 @@
 cess
-Chunk(chunk
+Piece(piece
 );%0A 
@@ -1564,12 +1564,146 @@
 send();%0A%7D;%0A%0A
+export default (url, callback) =%3E %7B%0A  return fetchSupported%0A    ? streamJsonFetch(url, callback)%0A    : streamJsonXHR(url, callback);%0A%7D

implement stream json using fetch