xhr-readline
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

xhr-readline

Read large XMLHttpRequests line by line. This package enables parsing of contents as soon as they come in over the wire.

export function readLineStream(
  xhr: XMLHttpRequest,
  onLine: ( line: string ) => void,
  onDone: () => void = noop,
  onError: ( error: any ) => void = logError
)

should tell you what you need to know ;)

const url = '/assets/test.lines';
const xhr = new XMLHttpRequest();
xhr.open( 'GET', url );
readLineStream( xhr, line => console.log( line ) );
xhr.send();

since you pass in the xhr object, you retain control over it and can e.g. abort the request at any time.

Benchmark Idea

If you can spare the time, it would be interesting to see how memory consumption and speed is affected by using this function vs waiting for all the data to be completed and then just using split('\n').

Readme

Keywords

none

Package Sidebar

Install

npm i xhr-readline

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

4.88 kB

Total Files

6

Last publish

Collaborators

  • maxwellium