import { NNTP } from 'nntp-js' import { delimitedReader } from './delimited_reader.js' const CRLF = new Uint8Array([13, 10]) /** * nntp-js with its reply reader replaced by `delimitedReader` (see there for * the bugs it fixes; the empty-reply one hung XOVER of empty ranges forever). * The reader is created in `connect`, so that is overridden: the same steps * as nntp-js 1.0.4, with the other reader. */ const proto = NNTP.prototype as any if (!proto.__delimitedReader) { proto.__delimitedReader = true proto.connect = async function (this: any, readermode = false, timeout: number | undefined = undefined, socket?: any) { try { this.sock = socket ?? this._createSocket(timeout) // The first reply is always the one-line welcome. this.byteReader = delimitedReader(this.sock, CRLF) this.welcome = new TextDecoder('utf-8').decode(await this._getresp()) this.caps = undefined this.connected = true await this.getcapabilities() this.readermodeAfterauth = false if (readermode && !this.caps.READER) { await this._setreadermode() if (!this.readermodeAfterauth) { this.caps = undefined await this.getcapabilities() } } } catch (error) { this.sock?.end() throw error } } } export { NNTP }