Skip to content

Instantly share code, notes, and snippets.

@corburn
Created December 30, 2017 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corburn/bb669e27f66e85362d8168905ebaddb0 to your computer and use it in GitHub Desktop.
Save corburn/bb669e27f66e85362d8168905ebaddb0 to your computer and use it in GitHub Desktop.
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