Created
December 30, 2017 21:22
-
-
Save corburn/bb669e27f66e85362d8168905ebaddb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var query = 'gopher'; | |
fetch('/large.csv').then(function(response) { | |
var reader = response.body.getReader(); | |
var partialRecord = ''; | |
var decoder = new TextDecoder(); | |
function search() { | |
return reader.read().then(function(result) { | |
partialRecord += decoder.decodde(result.value || new Uint8Array, { stream: !result.done }); | |
// query logic... | |
// Call reader.cancel('No more reading needed.'); when result found early. | |
if (result.done) { | |
throw Error('Count not find value after ' + query); | |
} | |
return search(); | |
}); | |
} | |
return search(); | |
}).then(function(result) { | |
console.log('Got the result! It's "' + result + '"'); | |
}).catch(function(err) { | |
console.log(err.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment