Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@logdna/tail-file

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@logdna/tail-file - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

.nvmrc

8

CHANGELOG.md

@@ -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 @@

8

lib/tail-file.js

@@ -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)) {

2

package.json
{
"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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc