UNPKG

gazeplotter

Version:

Gazeplotter is a Svelte application for visualizing eye-tracking data.

31 lines (30 loc) 894 B
/** * Responsible for parsing the stream of const from the eye tracking file to chunks of text. * * The stream is decoded using a TextDecoderStream. * File is assumed to be always complete, there is no need to check for end of file. */ export class EyeParser { rs; reader; isDone = false; constructor(rs, decoder = new TextDecoderStream()) { this.rs = rs.pipeThrough(decoder); this.reader = this.rs.getReader(); } /** * Parses one chunk of text from the stream. * @returns {Promise<string>} The chunk of text. * @throws {Error} If the parser is done. */ async getTextChunk() { if (this.isDone) throw new Error('EyeParser is done'); const { value, done } = await this.reader.read(); if (done) { this.isDone = true; return ''; } return value; } }