| 304 | } |
| 305 | |
| 306 | function streamOnEnd(this: StreamState): void { |
| 307 | let line = this.partial |
| 308 | if (line.endsWith('\r')) { |
| 309 | line = line.slice(0, -1) |
| 310 | } |
| 311 | if ( |
| 312 | this.currentLineIndex >= this.offset && |
| 313 | this.currentLineIndex < this.endLine |
| 314 | ) { |
| 315 | if (this.truncateOnByteLimit && this.maxBytes !== undefined) { |
| 316 | const sep = this.selectedLines.length > 0 ? 1 : 0 |
| 317 | const nextBytes = this.selectedBytes + sep + Buffer.byteLength(line) |
| 318 | if (nextBytes > this.maxBytes) { |
| 319 | this.truncatedByBytes = true |
| 320 | } else { |
| 321 | this.selectedLines.push(line) |
| 322 | } |
| 323 | } else { |
| 324 | this.selectedLines.push(line) |
| 325 | } |
| 326 | } |
| 327 | this.currentLineIndex++ |
| 328 | |
| 329 | const content = this.selectedLines.join('\n') |
| 330 | const truncated = this.truncatedByBytes |
| 331 | this.mtimeReady.then(mtimeMs => { |
| 332 | this.resolve({ |
| 333 | content, |
| 334 | lineCount: this.selectedLines.length, |
| 335 | totalLines: this.currentLineIndex, |
| 336 | totalBytes: this.totalBytesRead, |
| 337 | readBytes: Buffer.byteLength(content, 'utf8'), |
| 338 | mtimeMs, |
| 339 | ...(truncated ? { truncatedByBytes: true } : {}), |
| 340 | }) |
| 341 | }) |
| 342 | } |
| 343 | |
| 344 | function readFileInRangeStreaming( |
| 345 | filePath: string, |