@logdna/tail-file
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -0,1 +1,9 @@ | ||
# 2022-04-15, Version 2.2.0 (Stable) | ||
* [[9dbe1edf07](https://github.com/logdna/tail-file-node/commit/9dbe1edf07)] - fix: `destroyOnReturn` backward compatibility for node (Darin Spivey) | ||
* [[860045ec12](https://github.com/logdna/tail-file-node/commit/860045ec12)] - **(SEMVER-MINOR)** fix: Necessary changes for asyncIterators in recent version of node (Darin Spivey) | ||
* [[a6dc7baa3d](https://github.com/logdna/tail-file-node/commit/a6dc7baa3d)] - fix: Fix flakey test (Darin Spivey) | ||
* [[215b293099](https://github.com/logdna/tail-file-node/commit/215b293099)] - fix: Bump node versions for CI (Darin Spivey) | ||
* [[b9453b39d4](https://github.com/logdna/tail-file-node/commit/b9453b39d4)] - fix: README should explain a clean shutdown (Darin Spivey) | ||
# 2022-03-14, Version 2.1.1 (Stable) | ||
@@ -2,0 +10,0 @@ |
@@ -139,3 +139,9 @@ 'use strict' | ||
async _readChunks(stream) { | ||
for await (const chunk of stream) { | ||
// For node 16 and higher: https://nodejs.org/docs/latest-v16.x/api/stream.html#readableiteratoroptions | ||
/* istanbul ignore next */ | ||
const iterator = stream.iterator | ||
? stream.iterator({destroyOnReturn: false}) | ||
: stream | ||
for await (const chunk of iterator) { | ||
this[kStartPos] += chunk.length | ||
@@ -142,0 +148,0 @@ if (!this.push(chunk)) { |
{ | ||
"name": "@logdna/tail-file", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A node.js version of unix's `tail -f` command", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,2 +20,3 @@ [![Coverage Status](https://coveralls.io/repos/github/logdna/tail-file-node/badge.svg?branch=main)](https://coveralls.io/github/logdna/tail-file-node?branch=main) | ||
* [Example using `readline`](#example-using-readline) | ||
* [Example for Clean Shutdown](#example-for-clean-shutdown) | ||
* **[Events](#events)** | ||
@@ -150,2 +151,42 @@ * [Event: 'flush'](#event-flush) | ||
### Example for Clean Shutdown | ||
`TailFile` will call `flush()` when `quit()` is called. Therefore, to exit cleanly, | ||
one must simply await the `quit` call. If the implementation wishes to keep track of | ||
the last position read from the file (for resuming in the same spot later, for example), | ||
then a simple listener can be added to always track the file position. That way, when | ||
`quit()` is called, it will get properly updated. | ||
```js | ||
const TailFile = require('@logdna/tail-file') | ||
let position // Can be used to resume the last position from a new instance | ||
const tail = new TailFile('./somelog.txt') | ||
process.on('SIGINT', () => { | ||
tail.quit() | ||
.then(() => { | ||
console.log(`The last read file position was: ${position}`) | ||
}) | ||
.catch((err) => { | ||
process.nextTick(() => { | ||
console.error('Error during TailFile shutdown', err) | ||
}) | ||
}) | ||
}) | ||
tail | ||
.on('flush', ({lastReadPosition}) => { | ||
position = lastReadPosition | ||
}) | ||
.on('data', (chunk) => { | ||
console.log(chunk.toString()) | ||
}) | ||
.start() | ||
.catch((err) => { | ||
console.error('Cannot start. Does the file exist?', err) | ||
throw err | ||
}) | ||
``` | ||
## Events | ||
@@ -279,3 +320,3 @@ | ||
This function closes all streams and exits cleanly. The parent `TailFile` stream will be | ||
This function calls `flush`, then closes all streams and exits cleanly. The parent `TailFile` stream will be | ||
properly ended by pushing `null`, therefore an `end` event may be emitted as well. | ||
@@ -312,3 +353,3 @@ | ||
In these cases, `TailFile` will stop polling and wait until data is flowing before | ||
polling resumes. | ||
polling resumes. | ||
@@ -340,2 +381,2 @@ ### Log Rolling During Backpressure | ||
[push]: https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_readable_push_chunk_encoding | ||
[high water]: https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_readable_readablehighwatermark | ||
[high water]: https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_readable_readablehighwatermark |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46551
11
451
378