npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ocubist/file-stream-manager

v0.5.1

Published

DESCRIPTION

Readme

File Stream Manager

Description

The File Stream Manager provides a comprehensive set of utilities for managing file streams in Node.js environments. It allows for opening, reading, writing, flushing, and closing file streams, along with managing subscriptions and tracking usage counts. This package is particularly useful for applications requiring robust file management, such as logging systems, data processing pipelines, or any scenario where efficient and controlled file I/O operations are crucial.

Key Functions:

  • useFileStreamManager: A wrapper function that provides a unified interface for managing file streams.
    • open: Opens the file stream.
    • close: Closes the file stream.
    • write: Writes data to the file stream.
    • read: Reads data from the file stream.
    • flush: Flushes the file stream.
    • subscribe: Subscribes to the file stream.
    • unsubscribe: Unsubscribes from the file stream.
    • getUsageCount: Retrieves the usage count for the file stream.
    • isFileStreamOpen: Checks if the file stream is currently open.
  • getOpenFileStreams: Retrieves a list of all currently open file streams by their file paths.
  • forceCloseOfAllFileStreams: Forces the closure of all active file streams, typically used for cleanup or shutdown processes.

Installation

To install the File Stream Manager, use npm or yarn:

npm install @ocubist/file-stream-manager
# or
yarn add @ocubist/file-stream-manager

Usage

Basic Example

Here's a basic example demonstrating how to use the useFileStreamManager to open, write, and close a file stream:

import { useFileStreamManager } from "@ocubist/file-stream-manager";

const filePath = "./example.txt";
const fileManager = useFileStreamManager(filePath);

(async () => {
  await fileManager.open();
  fileManager.write("Hello, world!");
  fileManager.flush();
  const content = await fileManager.read();
  console.log(content); // Should output: Hello, world!
  await fileManager.close();
})();

Advanced Example with POST Request

Here’s an advanced example showing how you might use the useFileStreamManager in combination with a POST request handler to log data into a file:

import { useFileStreamManager } from "@ocubist/file-stream-manager";
import express from "express";

const app = express();
const filePath = "./log.txt";
const fileManager = useFileStreamManager(filePath);

app.use(express.json());

app.post("/log", async (req, res) => {
  try {
    await fileManager.open();
    fileManager.write(JSON.stringify(req.body) + "\n");
    fileManager.flush();
    res.status(200).send("Logged");
  } catch (error) {
    res.status(500).send("Failed to log");
  } finally {
    await fileManager.close();
  }
});

app.listen(3000, () => console.log("Server running on port 3000"));

API Documentation

Docs

License

The File Stream Manager is licensed under the MIT License. See the LICENSE file for more information.