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

file-timestamp-stream

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-timestamp-stream

Writing stream with file rotating based on timestamp

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132
decreased by-30.16%
Maintainers
1
Weekly downloads
 
Created
Source

file-timestamp-stream

Build Status Coverage Status npm

This module creates stream.Writable to a file which is automatically rotated based on current time.

Installation

npm install file-timestamp-stream

Additionally for Typescript:

npm install -D @types/node

Usage

Example:

const FileTimestampStream = require('file-timestamp-stream')

Typescript:

import FileTimestampStream from 'file-timestamp-stream'

Options

  • newFilename is a custom function with path as an only argument which returns new filename (default: returns new filename based on path and current time)
  • flags is a string with flags for opened stream (default: 'a')
  • fs is a custom fs module (optional)
  • path is a template for new filenames (default: 'out.log')

Example:

Basic path based on strftime parameters:

const stream = new FileTimestampStream({
  path: '%Y-%m-%dT%H.log',
  flags: 'a'
})

Custom filename generator:

const strftime = require('ultra-strftime')

// count how many files was created
let counter = 0

const stream = new FileTimestampStream({
  path: '%Y-%m-%dT%H:%M.log',
  newFilename
})

function newFilename (path) {
  const filename = strftime(path)
  if (filename !== stream.currentFilename) counter++
  return filename
}

Properties

  • currentFilename contains last opened filename
  • stream contains fs.WriteStream object

Path template format

Path can contain strftime specifiers.

License

Copyright (c) 2017-2018 Piotr Roszatycki piotr.roszatycki@gmail.com

MIT

Keywords

FAQs

Package last updated on 07 Jul 2018

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc