UNPKG

@kayahr/ed-journal

Version:

Typescript library to read/watch the player journal of Frontier's game Elite Dangerous

76 lines (75 loc) 3.02 kB
/** * Reads lines from a UTF-8 encoded file. */ export declare class LineReader implements AsyncIterable<string>, AsyncDisposable { /** The read buffer. */ private readonly buffer; /** The file to read from. Null if file is not open. */ private readonly file; /** The current read position in the file. */ private readPosition; /** The current offset in the text stream. */ private currentOffset; /** The current line in the text stream. */ private currentLine; /** The current start index in the buffer. */ private bufferStart; /** The current end index in the buffer. */ private bufferEnd; /** The buffered line. */ private bufferedLine; /** Text decoder used to decode UTF-8 line into JavaScript string. */ private readonly decoder; /** * Constructs a new line reader reading from the given file and position. * * @param file - The file to read from. * @param offset - The file offset to start reading from. * @param line - The line number to start counting with. * @param bufferSize - The size of the read buffer in bytes. */ private constructor(); /** @inheritdoc */ [Symbol.asyncDispose](): Promise<void>; /** * Creates a new line reader reading from the given file and position. * * @param filename - The file to read from. * @param offset - The file offset to start reading from. Defaults to 0 (Beginning of file). * @param line - The line number to start counting with. Defaults to 1 (First line). * @param bufferSize - The size of the read buffer in bytes. Defaults to 8 KB. * @returns The created line reader. */ static create(filename: string, offset?: number, line?: number, bufferSize?: number): Promise<LineReader>; /** * Returns the byte offset from which the next line will be read. * * @returns The byte offset from which the next line will be read. */ getOffset(): number; /** * Returns the line from which the next line will be read. * * @returns The line from which the next line will be read. */ getLine(): number; /** * Closes the file reader and releases the file handle it uses. */ close(): Promise<void>; /** * Reads the next line from the file and returns it. A line must be terminated by a line break (LF or CRLF). Method * returns null if there is currently no complete line to return. You can call the method again to try again (In * case the file is still growing). The returned string includes the line terminated (LF or CRLF) so you have to * strip it yourself if necessary. * * @returns The read line or null if no more complete lines are currently present. */ next(): Promise<string | null>; /** * Reads all lines until the end of the file. * * @yields The read lines as a generator. */ [Symbol.asyncIterator](): AsyncGenerator<string>; }