Socket
Socket
Sign inDemoInstall

tail-file-stream

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

tail-file-stream


Version published
Weekly downloads
65K
decreased by-9.27%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

tail-file-stream

tail-file-stream is a library that provides a streaming interface for reading a file that can be appended. It implements the Node.js fs.ReadStream functionality and watches the file for changes. When the file is appended, the stream emits a 'data' event with the new data.

  • Install
  • Usage
  • API
  • License

Install

npm i tail-file-stream --save

Usage

const { createReadStream } = require('tail-file-stream')

const stream = createReadStream('./foo.txt')

stream.on('data', (chunk) => {
  // Emits when has new data
})
stream.on('eof', () => {
  // Emits when reaches the end of the file
})
stream.on('end', () => {
  // Emits when stream ends
})

setTimeout(() => {
  // Stop watching the file
  stream.unwatch()
}, 10000)

API

createReadStream(path, [options])

Creates a new TailFileStream instance.

  • path <string> The file path to be read.
  • options <Object> Options for the stream.
    • flags <string> See support of file system flags. Default: 'r'.
    • mode <number> Default: 0o666.
    • start <number> The byte offset to start reading from. Default: 0.
    • end <number> The byte offset to stop reading. Default: Infinity.
    • highWaterMark <number> The maximum number of bytes to store in the internal buffer. Default: 64 * 1024.
    • autoWatch <boolean> If true, the file will be watched for changes from the beginning. Default: true.
    • persistent <boolean> Indicates whether the process should continue to run as long as files are being watched. Default: true.
  • Returns: TailFileStream The stream instance.
TailFileStream

The TailFileStream class extends the Node.js Readable stream.

TailFileStream emits the following events:

  • close - Emits when the file is closed.
  • eof - Emits when reaches the end of the file.
  • open - Emits when the file is opened.
  • ready - Emits when the file is ready to be read.

TailFileStream has the following properties:

  • bytesRead <number> The number of bytes read from the file.
  • path <string> The file path.
  • pending <boolean> This property is true if the underlying file has not been opened yet, i.e. before the 'ready' event is emitted.
  • watching <boolean> Indicates whether the file is being watched.
  • waiting <boolean> Indicates whether the stream is waiting for file changes.

TailFileStream has the following methods:

  • watch() - Starts watching the file for changes.
  • unwatch() - Stops watching the file. If the stream is waiting for file changes, it will be closed. If the stream is reading, the data will be read until the end of the file and then it will be closed.

License

MIT

Keywords

FAQs

Last updated on 14 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc